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
mkdir -p data/shard0/rs0 data/shard0/rs1 data/shard0/rs2 | |
mongod --replSet s0 --logpath "s0-r0.log" --dbpath data/shard0/rs0 --port 37017 --fork --shardsvr | |
mongod --replSet s0 --logpath "s0-r1.log" --dbpath data/shard0/rs1 --port 37018 --fork --shardsvr | |
mongod --replSet s0 --logpath "s0-r2.log" --dbpath data/shard0/rs2 --port 37019 --fork --shardsvr | |
mongo --port 37017 | |
config = {_id: "s0", members: [ | |
{_id: 0, host: "localhost:37017" }, | |
{_id: 1, host: "localhost:37018" }, | |
{_id: 2, host: "localhost:37019" }]}; |
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
# Writes the class hierarchy of the core Ruby classes. | |
$nodes = Hash.new | |
module Hack # Hack to keep Node out of the result! | |
class Node | |
attr_reader :cls | |
attr_accessor :children | |
def initialize(c) | |
@cls = c |
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
BasicObject | |
Object (Kernel) | |
Module | |
Class | |
NilClass | |
Data | |
TrueClass | |
FalseClass | |
Encoding | |
String (Comparable) |
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 Circle | |
attr_reader :r | |
def initialize(x = 0, y = 0, r = 1) | |
@x = x | |
@y = y | |
@r = r | |
end | |
def center |
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 Animal | |
def initialize(name) | |
@name = name | |
end | |
def speak() | |
"#{@name} says #{sound()}" | |
end | |
end | |
class Cow < Animal |
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 re | |
import sys | |
pattern = re.compile(r'"[\w]+":') | |
all = set([]) | |
for line in sys.stdin: | |
keys = re.findall(pattern, line) | |
all.update(keys) | |
print all |
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
/* | |
* bypass.c | |
* | |
* Try this on an x86 machine. It does **not** print "1". | |
*/ | |
#include <stdio.h> | |
void weird() { | |
int a; |
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
arg = {'x': 0} | |
def f(param): | |
same_ids = id(arg) == id(param) | |
different_ids = not same_ids | |
param = {'y': 4} | |
arg_changed = 'y' in arg | |
print('Call by value: {}'.format(different_ids)) | |
print('Call by sharing: {}'.format(same_ids and not arg_changed)) | |
print('Call by reference: {}'.format(same_ids and arg_changed)) |
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
# Runtimes for various complexity functions, sort of. | |
# | |
# A hacked-together little Python3 script printing runtimes for various | |
# complexity functions to standard output. | |
# | |
# The script isn't very general or customizable; you have to edit the | |
# source code to explore different functions or use different values | |
# of n. | |
import math |
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
# 10-7-4 Water Jug Problem | |
# Get 2 units of water in the 7-container or the 4-container | |
# Starting state is (0,7,4) | |
# Operations are F10, F7, F4, T107, T104, T710, T74, T410, T47 | |
# Goal states are (x,2,z) and (x,y,2) | |
operations = { | |
'F10' : lambda x, y, z: [10, y, z], |