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
//taken from Object Oriented Javascript by Stoyan Stefanov | |
var Hero() { | |
this.occupation = "Ninja!" | |
this.say = function() { | |
return "I'm a " + this.occupation; | |
} | |
} | |
/* correct invocation of constructor function |
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
sudo apt-get install libpq-dev | |
#I'm running postgresql-9.1. Match the version to that of your server. | |
sudo apt-get install postgresql-server-dev-9.1 | |
sudo apt-get install python-dev | |
#Now workon your virtualenv and pip install psycopg2 |
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
*filter | |
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 | |
-A INPUT -i lo -j ACCEPT | |
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT | |
# Accept all established inbound connections | |
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
# Allow all outbound traffic - you can modify this to only allow certain traffic |
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" | |
) |
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
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
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
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
/******************************************************************************************************* | |
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
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/ |