IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts The latest public snipts.

showing 1-20 of 100 snipts
  • Extract domain name from a full url
    /**
     * Function to get the exact domain name
     * @example: given http://www.example.com/dir1/file.php , returns www.example.com
    /**/
    function getDomain($url){
    	$domainName = explode("/",$url);
    	if(isset($domainName[2])) return $domainName[2];
    	else return NULL;
    }#end getDomain
    

    copy | embed

    0 comments - tagged in  posted by artilibere on Sep 03, 2010 at 8:19 a.m. EDT
  • A Friendly print_r version
    /**
     * Friendly print_r version
     **/
    function print_arr($variabile, $text='', $return=FALSE){
      if($text<>'') $text=" $text=";
      $type=gettype($variabile);
      switch($type){
          case "array":
          case "object":
              #$out="<p><pre>$text".var_export($variabile,TRUE)."</pre></p>";
              $out="<p><pre>$text".print_r($variabile,TRUE)."</pre></p>";
              break;
          case "NULL":
              $str="<p>NULL</p>";
          case "string":
          default:
              if(!isset($str)) $str=strval($variabile);
             $out="<p><pre>#".$type."[".strlen($str)."]:$text".($str)."</pre></p>";
              break;
      }
      if(!$return) echo $out;
      else return $out;
    }#end print_arr
    

    copy | embed

    0 comments - tagged in  posted by artilibere on Sep 03, 2010 at 8:10 a.m. EDT
  • Generate a random numeric zero-padded string
    /**
     * Function to generate a random numeric zero-padded string 
     * @param int $minChar Minimum character of the numer
     * @param int $maxChar Maximum character of the numer
     **/
    function getRandom($minChar=5, $maxChar=9){
    	$min=pow(10,$minChar-1);
    	$max=pow(10,$maxChar)-1;
    	list($usec, $sec) = explode(' ', microtime());
    	srand((float) $sec + ((float) $usec * 100000));
    	return str_pad(rand($min,$max),$maxChar,"0",STR_PAD_LEFT);
    }#end getRandom
    

    copy | embed

    0 comments - tagged in  posted by artilibere on Sep 03, 2010 at 8:08 a.m. EDT
  • get the index of the first occurrence of an object by class (using a block)
    /*
     * Some references:
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObjectPassingTest:
     *
     */
    
    /* Predeclare a block */
    BOOL (^IsSameClass)(id, NSUInteger, BOOL *) = ^(id element, NSUInteger idx, BOOL * stop) {
        *stop = [element isKindOfClass:UITabBar.class];
        return *stop;
    };
    	
    NSUInteger index = [myNSArray indexOfObjectPassingTest:IsSameClass];
    
    
    /* Using a block literal */
    NSUInteger index = [myNSArray indexOfObjectPassingTest:^(id element, NSUInteger idx, BOOL * stop){ 
        *stop = [element isKindOfClass:UITabBar.class];
        return *stop;
    }];
    

    copy | embed

    0 comments - tagged in  posted by jonatasmiguel on Sep 03, 2010 at 7:45 a.m. EDT
  • Euler 13
    #include<fstream>
    using namespace std;
    
    long l1[1]={50},l2[1]={50};
    long add(int x[1000],int y[1000])
    {
         long t,r,p,l,i,j;
         if(l1[0]>l2[0])
            l=l1[0];
         else
            l=l2[0];
         x[l]=y[l]=0;
         if(l2[0]==l)
             for(i=l1[0];i<l2[0];i++)
                 x[i]=0;
         else
             for(i=l2[0];i<l1[0];i++)
                 y[i]=0;
         for(i=0;i<l1[0]/2;i++)
         {
                               t=x[i];
                               x[i]=x[l1[0]-i-1];
                               x[l1[0]-i-1]=t;
         }
         for(i=0;i<l2[0]/2;i++)
         {
                               t=y[i];
                               y[i]=y[l2[0]-i-1];
                               y[l2[0]-i-1]=t;
         }
         for(i=0;i<l;i++) x[i]+=y[i];
            for(i=0;i<l;i++)
            {
                                r=x[i]%10;
                                p=x[i]/10;
                                x[i]=r;
                                x[i+1]+=p;
            }
            if(x[l]!=0)
               i++;
            for(j=0;j<i/2;j++)
            {
                     t=x[j];
                     x[j]=x[i-j-1];
                     x[i-j-1]=t;
            }
            return i;
    }
    int main()
    {
            ifstream read("input.txt");
            ofstream write("13.txt");
            int x[100][1000],i,j;
            char ch[100][51];
            for(i=0;i<100;i++)
               read>>ch[i];
            for(i=0;i<100;i++)
               for(j=0;j<50;j++)
                  x[i][j]=int(ch[i][j])-48;
            for(i=1;i<100;i++)
               l1[0]=add(x[0],x[i]);
            for(i=0;i<10;i++)
               write<<x[0][i];
    }
    

    copy | embed

    0 comments - tagged in  posted by SABB on Sep 03, 2010 at 7:00 a.m. EDT
  • Codeforces 5-B
    #include <iostream>
    #include <string>
    #include <deque>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
      deque<string> all;
      string str;
      int maxim=0;
      while(getline(cin,str))
        {
          all.push_back(str);
          maxim=max(maxim,(int)str.length());
        }
      int odd=0;
      for(int i=0;i<all.size();i++)
        {
          int spacestoadd=maxim-all[i].length();
          if(odd%2==1)//this means left is first
    	{
    	  for(int j=1;j<=spacestoadd;j++)
    	    {
    	      if(j<=spacestoadd/2)
    		all[i]=all[i]+" ";
    	      else
    		all[i]=" "+all[i];
    	    }
    	}
          else
    	{
    	  //int spacetoadd=maxim-all[i].length();
    	  for(int j=1;j<=spacestoadd;j++)
    	    {
    	      if(j<=spacestoadd/2)
    		all[i]=" "+all[i];
    	      else
    		all[i]=all[i]+" ";
    	    }
    	}
          all[i]="*"+all[i]+"*";
          odd+=(spacestoadd%2);
        }
      for(int i=0;i<maxim+2;i++)
    	cout<<"*";
          cout<<endl;
          for(int i=0.;i<all.size();i++)
    	cout<<all[i]<<endl;
          for(int i=0;i<maxim+2;i++)
    	cout<<"*";
          cout<<endl;
      return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by goharshady on Sep 03, 2010 at 5:00 a.m. EDT
  • Codeforces 5-A
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      int num=0;
      long long traffic=0;
      string st;
      while(getline(cin,st))
        {
          if(st[0]=='-')
    	num--;
          else if(st[0]=='+')
    	num++;
          else
    	{
    	  int len=st.length()-st.find(":")-1;
    	  traffic+=num*len;
    	}
        }
      cout<<traffic<<endl;
      return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by goharshady on Sep 03, 2010 at 5:00 a.m. EDT
  • Codeforces -4 B
    #include <conio.h>
    #include <iostream>
    #include <conio.h>
    using namespace std;
      int main()
        {
          int d,sum,s=0,s1=0;
          cin>>d>>sum;
          int min[d],max[d];
          for(int i=0;i<d;i++)
           {
             cin>>min[i]>>max[i];
             s+=min[i];
             s1+=max[i];
           }
          if(s1<sum||s>sum)
           cout<<"NO";
          else
            {
              int h[d];
              cout<<"YES"<<endl;
              for(int i=0;i<d;i++)
               h[i]=min[i];
              for(int i=0;i<d;i++)
                while(h[i]<max[i]&&sum>s)
                  {
                      h[i]++;
                      s++;
                  } 
              for(int i=0;i<d;i++)
               cout<<h[i]<<" ";
            }
          getch();
          return 0;
        }
    

    copy | embed

    0 comments - tagged in  posted by IMO on Sep 03, 2010 at 4:58 a.m. EDT
  • Codeforces -4 A
    #include <conio.h>
    #include <iostream>
    #include <conio.h>
    using namespace std;
      int main()
        {
          long int w,flag=0;
          cin>>w;
          if(w%2==1)
           cout<<"No";
          else  
            {
                for(int i=2;i<w&&flag==0;i+=2)
                 for(int j=i;j<w&&flag==0;j+=2)
                  if(i+j==w)
                    {
                     cout<<"Yes";
                     flag=1;
                    }
            }
          getch();
          return 0;
        }
    

    copy | embed

    0 comments - tagged in  posted by IMO on Sep 03, 2010 at 4:36 a.m. EDT
  • Codeforces 4-C
    #include <iostream>
    #include <set>
    #include <algorithm>
    #include <string>
    #include <sstream>
    using namespace std;
    
    set<string> users;
    
    int main()
    {
      int n;
      cin>>n;
      for(int i=0;i<n;i++)
        {
          pair<set<string>::const_iterator,bool> p;
          string req;
          cin>>req;
          p=users.insert(req);
          if(p.second)
    	cout<<"OK"<<endl;
          else
    	{
    	  for(int i=1;;i++)
    	    {
    	      stringstream sst;
    	      sst<<req<<i;
    	      string toadd;
    	      sst>>toadd;
    	      p=users.insert(toadd);
    	      if(p.second)
    		{
    		cout<<toadd<<endl;
    		break;
    		}
    	    }
    	}
        }
      return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by goharshady on Sep 03, 2010 at 3:00 a.m. EDT
  • Codeforces 4-B
    #include <iostream>
    using namespace std;
    int main()
    {
      int d,sumTime;
      cin>>d>>sumTime;
      int sumMin=0,sumMax=0;
      int min[d],max[d];
      for(int i=0;i<d;i++)
        {
        cin>>min[i]>>max[i];
        sumMin+=min[i];
        sumMax+=max[i];
        }
      if(sumTime<sumMin||sumTime>sumMax)
        cout<<"NO"<<endl;
      else
        {
          cout<<"YES"<<endl;
          int val[d];
          int sum=sumMin;
          for(int i=0;i<d;i++)
    	val[i]=min[i];
          for(int i=0;i<d;i++)
    	{
    	  while(val[i]<max[i]&&sum<sumTime)
    	    {
    	      val[i]++;
    	      sum++;
    	    }
    	}
          for(int i=0;i<d-1;i++)
    	cout<<val[i]<<" ";
          cout<<val[d-1]<<endl;
        }
      return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by goharshady on Sep 03, 2010 at 2:59 a.m. EDT
  • Codeforces 4-A
    #include <iostream>
    using namespace std;
    
    int main()
    {
      int n;
      cin>>n;
      if(n%2==1||n<=2)
        cout<<"NO"<<endl;
      else
        cout<<"YES"<<endl;
      return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by goharshady on Sep 03, 2010 at 2:59 a.m. EDT
  • Use template filters in a script
    # Convert existing plain text description for workshops to HTML.
    # Loop through all workshops, extract the description field, 
    # run it through Django's linebreaks template filter, and save.
    
    from django.utils.html import linebreaks
    
    wkshps = Workshop.objects.all()
    
    for w in wkshps:
        w.desc = linebreaks(w.desc)
        w.save()
    

    copy | embed

    0 comments - tagged in  posted by shacker on Sep 02, 2010 at 5:46 p.m. EDT
  • ProjectEuler25
    #include <iostream>
    #include <conio.h>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
        int i = 0;
        while (true)
        {
              i++;
              if (floor(i * log10((1+sqrt(5))/2) - log10(sqrt(5))) + 1 == 1000)
                 break;
        }
        cout << i;
        getch();
    }
    

    copy | embed

    0 comments - tagged in  posted by sepehrmousavi on Sep 02, 2010 at 5:32 p.m. EDT
  • NullPointer check - Intellij Live Template
    if($1$ == null) {
        throw new NullPointerException("$1$");
    }
    

    copy | embed

    0 comments - tagged in  posted by chilicat on Sep 02, 2010 at 4:19 p.m. EDT
  • TriangleYang
    #include <stdio.h>
    #define WIDTH  4
    
    int c(int,int);
    
    int main(void)
    {
    	int i,j,n=13;
    	printf("N=");
    	while(n>12)
    		scanf("%d",&n);
    
    	for(i=0;i<=n;++i)
    	{
    		//every line
    		for(j=0;j<(12-i)/2*WIDTH;j++)
    			printf(" ");
    		for(j=1;j<i+2;j++)
    			printf("%4d",c(i,j));
    		printf("\n");
    	}
    	system("PAUSE");	
    	return 0;
    
    }
    
    int c(int x, int y)
    {
    	int z;
    	if((y==1)||(y==x+1))
    		return 1;
    	z=c(x-1,y-1)+c(x-1,y);
    	return z;
    }
    

    copy | embed

    0 comments - tagged in  posted by sohu2000000 on Sep 02, 2010 at 2:06 p.m. EDT
  • watchdog
    #!/usr/bin/env python
    
    import time
    import sys
    import os
    import shutil
    from sets import Set
    
    dir = sys.argv[1]
    dirList = os.listdir(dir)
    fileList = set()
    
    
    while len(fileList) <= 105:
        time.sleep(60)
        for d in dirList:
            if "Flavobacteria" in d or "Gammaproteobacteria" in d or "Alphaproteobacteria" in d:
                fileList.add(d)
    
    """
    for d in dirList:
        if "Flavobacteria" in d or "Gammaproteobacteria" in d or "Alphaproteobacteria" in d:
            fileList.append(d)
    """     
    for f in fileList:
        fullpath = dir + f
        shutil.copy2(fullpath,"/Users/user/Dropbox/mimas_function")
    

    copy | embed

    0 comments - tagged in  posted by dgg32 on Sep 02, 2010 at 8:41 a.m. EDT
  • php in html via .htaccess
    AddType application/x-httpd-php .php .htm .html
    

    copy | embed

    0 comments - tagged in  posted by dobersby on Sep 02, 2010 at 5:09 a.m. EDT
  • set gov in android
    echo "nameofgovernor" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    

    copy | embed

    0 comments - tagged in  posted by defyenterprises on Sep 02, 2010 at 1:07 a.m. EDT
  • list avail govs in cpu android
    cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
    

    copy | embed

    0 comments - tagged in  posted by defyenterprises on Sep 02, 2010 at 1:07 a.m. EDT
Sign up to create your own snipts, or login.