Skip to content

Instantly share code, notes, and snippets.

#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@gennad
gennad / UrlShortenerPos.java
Created December 2, 2010 12:38
Generates the number of position for your url in url shortener
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
import java.util.Stack;
import java.util.regex.Matcher;
public class Secret {
private String secretCode = "It's a secret";
private String getSecretCode(){
return secretCode;
}
}
/**
* Connects to the database
*
* Connects to the database and some other
* discription....
* @param $type some variable
*/
function connect($type = '') {
//some code
}
@gennad
gennad / GoldenNumber.cpp
Created December 22, 2010 15:59
GoldenNumber.cpp
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <map>
int getIntVal(std::string strConvert) {
int intReturn;
@gennad
gennad / Debug output
Created January 9, 2011 18:42
Debug output
Initial:
x.x.x.x
x.x.x
x.x...x
x.x.x
x.x.x.x
1.
xOx.x.x
xOx.x
@gennad
gennad / ObjectSizeFetcher.java
Created February 2, 2011 08:32
Object size fetcher
import java.lang.instrument.Instrumentation;
public class ObjectSizeFetcher {
private static Instrumentation instrumentation;
public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}
public static long getObjectSize(Object o) {
@gennad
gennad / XmlIndenter.java
Created February 9, 2011 09:36
Creates indents in the xml file
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
@gennad
gennad / command.py
Created March 2, 2011 17:42
Command - GoF
class Command:
def execute(self):
raise NotImplementedError()
class Accelerator(Command):
def __init__(self, car):
self.car = car
def execute(self):
@gennad
gennad / lazyinit.py
Created March 2, 2011 17:40
Lazy initialization - GoF
class LazyCalc:
def __init__(self):
self.dict = {}
def calc(self, n):
if n not in self.dict:
def recursion(n):
if n <= 1:
return 1