This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################################################### | |
# 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. # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from datetime import datetime | |
#################### | |
# implementation 1 # | |
#################### | |
# basic implementation | |
def quicksort1(l): | |
size = len(l) | |
# stop condition for reqursive calls | |
if size<=1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
OlderNewer