Skip to content

Instantly share code, notes, and snippets.

View rtoal's full-sized avatar
💭
Copying and pasting

Ray Toal rtoal

💭
Copying and pasting
View GitHub Profile
@rtoal
rtoal / mongo-getting-started.js
Last active January 10, 2017 06:58
Getting started with the mongo shell
show dbs
use hello
db.people.insert({name: "Abdul", age: 22, likes: ["skiing", "hiking"]})
db.people.insert({name: "Barbara", age: 20, country: "UK"})
db.people.insert({name: "Chi", age: 40, country: "CN",
job: {title: "welder", salary: {currency: "EUR", amount: 50000}}})
@rtoal
rtoal / mongo-intermediate
Last active December 17, 2015 03:28
Transcript for an intermediate-level mongo demonstration
# Mongo not happy unless lots of open files
ulimit -n 2000
# Start server
sudo mongod --fork --syslog
# Already done
unzip all-films.zip
mongoimport -d mgo -c films all-films.json
@rtoal
rtoal / mongo-sharding-transcript.js
Created June 6, 2013 18:11
Transcript for the sharding example from a mongo workshop
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" }]};
@rtoal
rtoal / core-class-hiearchy.rb
Created July 17, 2013 03:06
Generates the tree of Ruby core classes that aren't themselves in any modules
# 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
@rtoal
rtoal / ruby-2.0.0p247-core-classes.txt
Created July 17, 2013 03:12
Output of gist 6017359 using Ruby 2.0.0p247
BasicObject
Object (Kernel)
Module
Class
NilClass
Data
TrueClass
FalseClass
Encoding
String (Comparable)
@rtoal
rtoal / circle.rb
Last active December 19, 2015 21:09
A trivial Ruby circle class
class Circle
attr_reader :r
def initialize(x = 0, y = 0, r = 1)
@x = x
@y = y
@r = r
end
def center
@rtoal
rtoal / animals.rb
Created July 17, 2013 07:32
Demonstration of Inheritance and Polymorphism in Ruby
class Animal
def initialize(name)
@name = name
end
def speak()
"#{@name} says #{sound()}"
end
end
class Cow < Animal
@rtoal
rtoal / find_json_properties.py
Created July 31, 2013 20:34
Guess the properties of a JSON file, read from stdin. Not perfect.
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
@rtoal
rtoal / bypass.c
Created November 4, 2013 04:03
A fun executable to try on a 32-BIT x86 machine. I wrote this years and years and years ago.
/*
* bypass.c
*
* Try this on an x86 machine. It does **not** print "1".
*/
#include <stdio.h>
void weird() {
int a;
@rtoal
rtoal / rubin.py
Created December 14, 2013 18:11
Rubin's "'Goto Considered Harmful' Considered Harmful" as a Python One-Liner
next((i for i,row in enumerate(a) if all(x == 0 for x in row)), -1)