Skip to content

Instantly share code, notes, and snippets.

💭
Copying and pasting

Ray Toal rtoal

💭
Copying and pasting
Block or report user

Report or block rtoal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rtoal
rtoal / mongo-getting-started.js
Last active Jan 10, 2017
Getting started with the mongo shell
View mongo-getting-started.js
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 Dec 17, 2015
Transcript for an intermediate-level mongo demonstration
View mongo-intermediate
# 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 Jun 6, 2013
Transcript for the sharding example from a mongo workshop
View mongo-sharding-transcript.js
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 Jul 17, 2013
Generates the tree of Ruby core classes that aren't themselves in any modules
View core-class-hiearchy.rb
# 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 Jul 17, 2013
Output of gist 6017359 using Ruby 2.0.0p247
View ruby-2.0.0p247-core-classes.txt
BasicObject
Object (Kernel)
Module
Class
NilClass
Data
TrueClass
FalseClass
Encoding
String (Comparable)
@rtoal
rtoal / circle.rb
Last active Dec 19, 2015
A trivial Ruby circle class
View circle.rb
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 Jul 17, 2013
Demonstration of Inheritance and Polymorphism in Ruby
View animals.rb
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 Jul 31, 2013
Guess the properties of a JSON file, read from stdin. Not perfect.
View find_json_properties.py
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 Nov 4, 2013
A fun executable to try on a 32-BIT x86 machine. I wrote this years and years and years ago.
View bypass.c
/*
* 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 Dec 14, 2013
Rubin's "'Goto Considered Harmful' Considered Harmful" as a Python One-Liner
View rubin.py
next((i for i,row in enumerate(a) if all(x == 0 for x in row)), -1)
You can’t perform that action at this time.