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 Node: | |
def __init__(self,val,parent=None): | |
self.val = val | |
self.parent = parent | |
self.left = None | |
self.right = None | |
def setLeft(self,node): | |
self.left = node |
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
#!/bin/bash | |
#Take project name as input | |
if [ -z "$1" ] | |
then | |
echo "Enter project name" | |
read proj | |
else | |
proj="$1" | |
fi |
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
#To get all sql queries sent by Django from py shell | |
import logging | |
l = logging.getLogger('django.db.backends') | |
l.setLevel(logging.DEBUG) | |
l.addHandler(logging.StreamHandler()) | |
#For more info, http://stackoverflow.com/questions/971667/django-orm-how-to-view-or-log-the-executed-query |
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 ways(amount, coin_types): | |
""" | |
Python implementation for the counting_change problem | |
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2 | |
Doesn't work for large numbers because we don't have tail call optimization in python | |
Time complexity analysis: Found an explanation at | |
http://wqzhang.wordpress.com/2009/06/09/sicp-exercise-1-14/ |
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
/******************************************************************************************************* | |
Checks if an object(instance) has the same properties of the same type with respect to a known | |
object(schema). | |
validate is especially useful to test whether the server side code sends JSON as expected by the client | |
Usage Example: | |
1. Create a sample expected object (sampleSchema). | |
2. When data(sampleInstance) is received, call validate(sampleSchema, sampleInstance) |
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
all: | |
gcc -Wall http_client.c -o http_client | |
clean: | |
rm *.o;rm http_client | |
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
var countNodes = function() { | |
var total = 1; | |
var count = function(node) { | |
var i, l; | |
l = node.children.length; | |
total += l; | |
for(i=0; i<l; i++) { | |
count(node.children[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
import "fmt"; | |
import "code.google.com/p/go-tour/pic" | |
func Pic(dx, dy int) [][]uint8 { | |
phew := make([][]uint8, dx) | |
for i := range phew { | |
phew[i] = make([]uint8, dy) | |
for j := range phew[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
package main | |
import ( | |
"fmt" | |
) | |
func approx(z, x float64) float64 { | |
z = z - (z*z - x)/2/z | |
return z | |
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
// Copyright 2011 The Go Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style | |
// license that can be found in the LICENSE file. | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) |
OlderNewer