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 urllib | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
#Enter your bitly username and apikey here | |
BITLY_USER = 'xxxxxx' | |
BITLY_API = 'xxxxxxxxxxxxxxxxxxxxxxxxx' |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
/* gobal declarations */ | |
int eax, ebx, ecx, edx, esi, edi; | |
unsigned char M[10000]; | |
int a[5]; | |
/* prototypes */ |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* Structs */ | |
typedef struct Variable | |
{ | |
char* identifier; | |
int value; | |
struct Variable* next; |
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
/* End cases, where str is atom or number */ | |
count(Str, Op, 0) :- atom(Str). | |
count(Str, Op, 0) :- number(Str). | |
/* Program */ | |
count(Str, Op, R) :- Str =..[A,B,C], | |
test(A, Op, R1), | |
count(B, Op, R2), | |
count(C, Op, R3), | |
R is R1 + R2 + R3. |
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
/* 6 differentiation rules */ | |
derive(X, X, 1). | |
derive(In, X, 0) :- atomic(In). | |
derive(In1+In2, X, Res1 + Res2) :- derive(In1, X, Res1), derive(In2, X, Res2). | |
derive(In1-In2, X, Res1 - Res2) :- derive(In1, X, Res1), derive(In2, X, Res2). | |
derive(In1*In2, X, In1 * Res1 + Res2 * In2) :- derive(In1, X, Res2), derive(In2, X, Res1). | |
derive(In1/In2, X, (In2 * Res1 - In1 * Res2)/In2*In2 ) :- derive(In1, X, Res1), derive(In2, X, Res2). |
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
simplify(X,Res) :- simple(X,Z), simple(Z,Res), !. | |
simple(X,X) :- atomic(X), ! . | |
simple(In, Res) :- In =.. [Ope, A], | |
simple(A, C), unary(Ope,C,Res). | |
simple(In, Res) :- In =.. [A,B,C], | |
simple(B, Res1), | |
simple(C, Res2), | |
simple(A, Res1, Res2, Res). |
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
-- PS5 Problem 1 | |
insert a pos l = | |
fst ( foldr | |
(\x (b,c) -> (if c==pos-1 then a:x:b else x:b, c+1 )) | |
((drop pos [a]),0) l) |
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
def gravatar_url(email, size=80): | |
"""Return the gravatar image for the given email address.""" | |
return 'http://www.gravatar.com/avatar/%s?d=identicon&s=%d' % \ | |
(md5(email.strip().lower().encode('utf-8')).hexdigest(), size) |
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 simulation program works as follows: | |
The Task class contains a list of tasks to run, and tracks block state. | |
The Task.next() function exposes the next function of the generator tasks it contains. | |
When a block is called (via Task.block(name_of_task)) all other tasks except for | |
name_of_task will be added to the internal Task blocklist. | |
Task.next() will skip over any tasks currently on the blocklist | |
during Round-Robin iteration. | |
Task.release_block() clears the block list, thus allowing all other tasks to continue running |
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
"""Translated from Haskell: | |
let sieve(p:xs) = p : sieve (filter (\ x -> x `mod` p /= 0) xs) in sieve [2..] | |
""" | |
from itertools import ifilter | |
def ints(k): | |
yield k | |
while True: | |
yield k |
OlderNewer