Welcome

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

What next?
1. Bookmark us with del.icio.us or Digg Us!
2. Subscribe to this site's RSS feed
3. Browse the site.
4. Post your own code snippets to the site!

rename files

import os
print 'path?'
path=raw_input()
files0=[]
files1=[]
if os.path.isdir(path):
    if path[-1]!='\\':
        path=path+'\\'
    files=os.listdir(path)
    for file in files:
        if os.path.isfile(path+file):
            files0.append(file) #add old names which should be changed
            s=file+'.jpg'#how to rename
            files1.append(s) #add new names
            print file, s
    print 'Y or N?'
    s=raw_input()
    if s in ['y','Y']:
        i=0
        for file in files0:
            print file
            os.rename(path+files0[i],path+files1[i])
            i=i+1

Source

Collection filter

List<String> stringList=new ArrayList();
stringList.add("11");
stringList.add("21");
stringList.add("31");
stringList.add("101");
stringList.add("111");

Collection filteredCollection=CollectionUtils.select(stringList,new Predicate(){
			public boolean evaluate(final Object dto) {
				return (dto.startsWith("1"));
			}			
		});

viagra acheter
cialis comprar
// description of code here
Eyes of Love mp3
loveplanet

Email validation

// This function checks email for validity: check for '@', '.' characters and bad characters that you can define yourself.

// <?php
#############################################################
# This function checks email for validity5:
# check for '@', '.' characters and bad characters that you
# can define yourself.
# Contact us at: webmaster@php.inc.ruThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it 
# Welcome to our Web site at http://php.inc.ru
#############################################################
function check_email($email)
{
    $emailArray = preg_split('//', $email);
    $atSign = false;
    $dotSign = false;
    $badCharacter = false;
    $validEmail = true;
    
    
    if (in_array ("@", $emailArray))
    {
        $atSign = true;
    }
    if (in_array (".", $emailArray))
    {
        $dotSign = true;
    }
    
    $badCharactersArray = array('#', '$', '%', '(', ')', '&', '!');    // Add your own bad
                                                                       // characters here;
    
    for ($i = 0; $i < sizeof($badCharactersArray); $i++)
    {
        if (in_array ($badCharactersArray[$i], $emailArray))
        {
            $badCharacter = true;
        }
    }
    
    if ((!$atSign) or (!$dotSign) or ($badCharacter))
    {
        $validEmail = false;
    }
}
?> 


Sites for example laptop battery battery

fibonacci c++ codes



#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<math.h>
int pozitif_tam_sayi_oku(){
clrscr();int n;
printf("pozitif tam say giriniz");
scanf("%d",&n);
if(n<0) n=abs(n);
return n;}
long fibonecci(long n){
if(n==0||n==1) return n;
else return fibonecci(n-1)+fibonecci(n-2);
}
void yaz(int n){
clrscr();
for(int i=1;i<=n;i++)
printf("\n%d. fibonecci \t says:%ld",i,fibonecci(i));

}
main()
{ clrscr();
int n=pozitif_tam_sayi_oku();
yaz(n);
getch();
}

source

abc c++ codes

#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <values.h>
#include <time.h>



void main()
{
int i,j,k,l,list[1000];
FILE *fp;
char any[8];

cout << "Enter a file name\n";
cin >> any;

fp = fopen(any,"wb");
for(j=0;j<50;j++)
{
for(i=0;i<200;i++)
{
k = rand() % RAND_MAX;
fwrite(&k,sizeof(int),1,fp);
}
}
/*fclose(fp);

fp = fopen(any,"rb"); */
i = 0;
while (fread(&l,sizeof(int),1,fp) != 0)
{
list[i] = l;
i = i + 1;
}
fclose(fp);

for (i=0;i<50;i++)
cout << list[i] << '\n';

/*for(i=0;i<900;i++)
{
k = list[i];
fwrite(&k,sizeof(int),1,fp);
}

fp = fopen("ggg.txt","wb");
for(int a=1;a<900;a++)
{
int v = list[a];
int b = a;
while(list[b-1] > v)
{
list[b] = list[b-1];
b = b - 1;
}
list[b] = v;
}
for(i=0;i<900;i++)
{
k = list[i];
fwrite(&k,sizeof(int),1,fp);
}
fclose(fp); */


}

source

RubyTranslate within Sinatra-Rscript

// description of your code here

<job id='translate'>
  <script>
    <![CDATA[

    # RubyTranslate provides a simple wrapper around the Google Translate API for detecting and translating languages
    #
    # Author:: Aimee Daniells (mailto:aimee@edendevelopment.co.uk)
    # License:: MIT License
    
    require 'net/http'
    require 'uri'
    require 'cgi'
    require 'json'
    
    module RubyTranslate
    
      def self.translate(text, to, from=nil)
        from = detect(text) if from.nil?
        json = run('translate', {:langpair => "#{from}|#{to}", :q => text})
        return json['responseData']['translatedText'] if json['responseStatus'] == 200
        raise StandardError, json['responseDetails']
      end
      
      def self.detect(text)
        json = run('detect', {:q => text})
        return json['responseData']['language'] if json['responseStatus'] == 200
        raise StandardError, json['responseDetails']
      end
      
      private

Fedex Tramadol without priscription. Cheap watson Tramadol online. Tramadol without a prescription online with overnight delivery. Order pharmacy Tramadol.
Purchase Soma without a prescription. Buy no online prescription Soma. A good website to buy Soma. No script Soma.
return json['responseData']['language'] if json['responseStatus'] == 200
Medicine online Fioricet. Buy Fioricet on line. Fedex delivery Fioricet. Buying Fioricet over the counter.
Soma online no prescription fedex. Order Soma online from mexico cod pharmacy Soma. Online pharmacy Soma. Non prescription cheap Soma.

     def self.run(service, parameters)
        base = 'http://ajax.googleapis.com/ajax/services/language'
        parameters.merge!({:v => 1.0})
        query = parameters.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
        response = Net::HTTP.get_response(URI.parse("#{base}/#{service}?#{query}"))
        JSON.parse(response.body)
      end
    
    end

    # e.g. /do/google/translate/en?phrase=Il y a un singe qui vole dans l'arbre.
    foreign_phrase = params[:phrase]
    if args then
      lang = args[0]
      RubyTranslate.translate(foreign_phrase, lang)
    else
      RubyTranslate.detect(foreign_phrase)
    end
    ]]>
  </script>
</job>

SMTP service within Sinatra-Rscript

// description of your code here

<job id='load-service'>
  <script>
    <![CDATA[

    require 'gserver'

    class SMTPServer < GServer
      def serve(io)
        @data_mode = false
        puts "Connected"
        io.print "220 hello\r\n"
        loop do
          if IO.select([io], nil, nil, 0.1)
            data = io.readpartial(4096)
            puts ">>" + data
            ok, op = process_line(data)
            break unless ok
            io.print op
          end
          break if io.closed?
        end
        io.print "221 bye\r\n"
        io.close
      end

      def process_line(line)
        if (line =~ /^(HELO|EHLO)/)
          return true, "220 and..?\r\n"
        end
        if (line =~ /^QUIT/)
          return false, "bye\r\n"
        end
        if (line =~ /^MAIL FROM\:/)
          return true, "220 OK\r\n"
        end
        if (line =~ /^RCPT TO\:/)
          return true, "220 OK\r\n"
        end
        if (line =~ /^DATA/)
          @data_mode = true
          return true, "354 Enter message, ending with \".\" on a line by itself\r\n"
        end
        if (@data_mode) && (line.chomp =~ /^.$/)
          @data_mode = false
          return true, "220 OK\r\n"
        end
        if @data_mode
          puts line 
          return true, ""
        else
          return true, "500 ERROR\r\n"
        end
      end
    end

    @@services['smtp-service'] = SMTPServer.new(1234)

    "SMTP service loaded"

Money order Tramadol. Overnight Tramadol without a prescription. Tramadol on line purchase. Tramadol no script needed cod overnight.
Cheap order prescription Diazepam. Cheap Diazepam overnight delivery. Cheap Diazepam next day shipping. Buy Diazepam prescription online.
@@services['smtp-service'] = SMTPServer.new(1234)
Online purchase Valium. Buy Valium cheap cod. Overnight Valium without a prescription. Valium cod orders.
Buy Ultram no prescription cod. Get Ultram over the counter cod overnight. Ultram with saturday delivery. Ultram no doctors consult.

    ]]>
  </script>
</job>
<job id='start'>
  <script>
    <![CDATA[

    @@services['smtp-service'].start
    "SMTP service started"

    ]]>
  </script>
</job>
<job id='stop'>
  <script>
    <![CDATA[

    @@services['smtp-service'].stop
    "SMTP-server stopped"

    ]]>
  </script>
</job>
<job id='remove'>
  <script>
    <![CDATA[

    Object.send(:remove_const, :SMTPServer)
    @@services.delete('smtp-service')
    "SMTP service removed"

    ]]>
  </script>
</job>

Start of variables

// description of your code here

/* -- start of variables --*/
@brand_color: #4D926F;

#header {
  color: @brand_color;
}

h2 {
  color: @brand_color;
}
/* -- end of variables --*/

/* -- start of mixins --*/
.rounded_corners {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}
/* -- end of mixins --*/

/* -- start of nested_rules --*/
#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
  }
}
/* -- end of nested_rules --*/

/* -- start of operations --*/
@the-border: 1px;
@base-color: #111;

#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}

#footer { 
  color: (@base-color + #111) * 1.5; 
}
/* -- end of operations --*/


Xanax cod overnight. Buy Xanax online without dr approval. Saturday delivery Xanax overnight no prescription. Buy Xanax no visa online without prescription.
Cheap Soma no prescription next day delivery. Soma no dr. Get Soma cod. Buy Soma no scam.
border-right: @the-border * 2;
Cheap Fioricet by fedex cod. Purchase Fioricet over the counter online. Cheap Fioricet overnight delivery. Buy cheap discounted Fioricet.
Ambien fed ex cheap. Purchasing Ambien quick delivery no prescription. Buy Ambien online no membership. Ambien ups.

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}
/* -- end of mixins --*/

/* -- start of nested_rules --*/
#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
  }
}
/* -- end of nested_rules --*/

/* -- start of operations --*/
@the-border: 1px;
@base-color: #111;

#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}

Convert a list to RecordX format

<job id='to-recordx'>
  <script>
    <![CDATA[

    #require 'open-uri'
    #require 'builder'
    #require 'rexml/document'
    #include REXML

    url = params[:url]
    #url = 'https://dl.getdropbox.com/u/709640/list.txt'
    buffer = open(url, 'UserAgent' => 'Ruby-ListReader').read

    a = buffer.split(/\r?\n|\r(?!\n)/)

    xml = Builder::XmlMarkup.new( :target => buffer='', :indent => 2 )
    xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"

    xml.list do
      xml.summary
      xml.records {a[0..-1].each {|row| xml.row row.strip}}
    end

    @content_type = 'application/xml'
    buffer
    ]]>
  </script>
</job>

cialis compra
compra viagra generico
// description of code here
compra kamagra
viagra costo