Skip to content

Instantly share code, notes, and snippets.

View huseyinyilmaz's full-sized avatar

Huseyin Yilmaz huseyinyilmaz

  • Balikesir, Turkey
View GitHub Profile
@huseyinyilmaz
huseyinyilmaz / set_prototype.js
Created August 22, 2010 21:01
Javascript prototypal inheritance samples
/*
Sets prototype of a object first way
*/
var a = {afunc:function(){alert("a");}};
var b = {bfunc:function(){alert("b");}};
a.__proto__ = b;
a.bfunc();
/*
Same thing with constructors.
@huseyinyilmaz
huseyinyilmaz / 11_digit_prime_number.py
Created October 9, 2010 09:41
11 digit prime number generator
# Searches for 11 digits prime numbers
#
# This one is really slow for big numbers
# def isprime(num):
# val = num-1L
# while not val == 1L :
# if num%val == 0L:
# #print str(num) + "%" + str(val) + "==0"
# return False
# val = val -1L
if __name__ == '__main__':
#get wordlist
f = open('wordlist.txt','r')
wordlist = [line.strip()for line in f]
f.close()
#get given words
f = open('words.txt')
words = [line[1:].strip()for line in f]
f.close()
#result will be stored in this list
@huseyinyilmaz
huseyinyilmaz / models.py
Created March 8, 2011 22:17
django models.py file for a sample prefilled database
from django.db import models
class Company(models.Model):
name = models.CharField(max_length=255,unique=True)
class Department(models.Model):
name = models.CharField(max_length=255)
company = models.ForeignKey(Company)
class Meta():
unique_together = (('name','company'))
@huseyinyilmaz
huseyinyilmaz / name.py
Created April 1, 2011 10:23
Simple twitter crawler that collects twitter user and user follower relationships.
#########################################################################################
# This scripts pulls twitter user information and follower relationships #
# using twitter REST API and stores them in an sqlite database. #
# Before using this one you have to run name.sh file to create sqlite3 database #
# that this script will use. #
# USAGE: #
# first create your database #
# $ ./name.sh #
# then add a user to your database as start point #
# $ python name.py yilmaz_huseyin # change twitter user name with any name you want. #
@huseyinyilmaz
huseyinyilmaz / quicksort.py
Last active September 25, 2015 09:57
various quicksort implementations
import random
from datetime import datetime
####################
# implementation 1 #
####################
# basic implementation
def quicksort1(l):
size = len(l)
# stop condition for reqursive calls
if size<=1:
@huseyinyilmaz
huseyinyilmaz / sqrt.py
Created April 7, 2011 13:07
square-root performance test between native implementation and Newton's method.
import random
import operator
from datetime import datetime
from math import sqrt
from functools import reduce
def better_gues(number,gues):
return ((number/gues) + gues) /2
def sqrt1(number,gues=None):
@huseyinyilmaz
huseyinyilmaz / len2.py
Created April 8, 2011 13:08
experimental implementation to native len method (do not use it.)
#!/usr/bin/python3
from functools import reduce
from operator import add
from datetime import datetime
def countIter2(i):
try:
i.__next__()
except StopIteration:
return 0
return 1 + countIter2(i)
@huseyinyilmaz
huseyinyilmaz / cups.py
Created May 25, 2011 05:13
my solution for 40 cups and 9 oranges problem.
#!/usr/bin/python3.2
from itertools import combinations
"""
You have 40 bowls, all placed in a line at exact intervals of 1 meter. You also have 9 oranges. You wish to place all the oranges in the bowls, no more than one orange in each bowl, so that there are no three oranges A, B, and C such that the distance between A and B is equal to the distance between B and C. How many ways can you arrange the oranges in the bowls?.
(http://www.bittorrent.com/company/about/developer_challenge)
"""
def find_count(orange_count=9,cup_count=40,start_point=0,l=[]):
"""
orange_count: how many oranges should be placed in cups. for our question it is 9.
cup_count: how many cups should be used
@huseyinyilmaz
huseyinyilmaz / imagewiththumbnails.py
Created July 22, 2011 07:11
A django thumbnail support example
class ImageWithThumbnail(models.Model):
name = models.CharField(max_length = 255)
image = models.ImageField(upload_to=settings.UPLOAD_ROOT,max_length=500,blank=True,null=True)
thumbnail = models.ImageField(upload_to=settings.UPLOAD_ROOT,max_length=500,blank=True,null=True)
def create_thumbnail(self):
# original code for this method came from
# http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/