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 fibonacci(): | |
a, b = 0, 1 | |
def f(): | |
nonlocal a,b | |
a, b = b, a+b | |
return a | |
return f | |
if __name__ == '__main__': | |
f = fibonacci() |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<html> | |
<head> | |
<title>Take Two</title> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="http://dimplejs.org/dist/dimple.v2.1.6.min.js"></script> | |
</head> | |
<body> | |
<h3>Time Spent per Adult User per day</h3> |
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 <libconfig.h> | |
/** | |
$ cat data.ini | |
position:{ | |
x = 50; | |
y = 100; | |
} | |
$ gcc -lconfig libconfig_example.c | |
$ ./a.out |
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
""" | |
Linked list implementation | |
""" | |
__author__ = "Satheesh Kumar Mohan <sathyz@gmail.com>" | |
class Node(object): | |
def __init__(self, value=None): | |
self.value = value | |
self.next = 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
maps = [ | |
'aijqy', #1 | |
'bkr', #2 | |
'cgls', #3 | |
'dmt', #4 | |
'ehnx', #5 | |
'uvw', #6 | |
'oz', #7 | |
'fp', #8 |
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 xml.dom.minidom import parse | |
def to_dict(node): | |
""" convert a given xmlnode to dict with its child tags as key and their | |
text as value""" | |
element = {} | |
for child in node.childNodes: | |
if child.hasChildNodes(): | |
element[child.tagName] = child.firstChild.wholeText | |
#print element |
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 sys | |
import unittest | |
class InvalidDateException(Exception):pass | |
def is_leap(year): | |
if year % 400 == 0: | |
return True | |
elif year % 100 == 0: | |
return False |
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
__author__ = "Satheesh Kumar Mohan <sathyz@gmail.com>" | |
MIN_WORD_SIZE=3 | |
class Node(object): | |
"""Every node in the Trie tree. Node has a marker True/False saying if it | |
the end of the word or not and children will have the next successive | |
character of the word so on. | |
Say if a word is 'ipl', root['i']:False -> node['p]:False-> node['l']:True""" |
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> | |
int get_nearest_square(int n, int low, int high){ | |
int low_sq, high_sq, mid; | |
if (high-low <= 1){ | |
low_sq = low * low; | |
high_sq = high * high; | |
return (n - low_sq < high_sq - n)? low_sq: high_sq; | |
} |
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 get_max_prod3(seq): | |
"""Given a sequence, find the 3 numbers which has max product.""" | |
min_seq = [1, 1] | |
max_seq = [-1, -1, -1] | |
for i in seq: | |
if i < 0: | |
if i < min_seq[0]: | |
min_seq[0] = i | |
elif i < min_seq[1]: | |
min_seq[1] = min_seq[0] |
NewerOlder