Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert Whitney robertjwhitney

View GitHub Profile
View css selectors
# multi-class selection
<div class="a b c">
</div>
.a.b { }
# parent - child selection
<div class="a">
View local_methods.rb
class Object
# Return a list of methods defined locally for a particular object. Useful
# for seeing what it does whilst losing all the guff that's implemented
# by its parents (eg Object).
def local_methods(obj = self)
(obj.methods - obj.class.superclass.instance_methods).sort
end
end
View gist:5232518
$ valgrind --version
valgrind-3.8.1
$ valgrind ./ex6
==56827== Memcheck, a memory error detector
==56827== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==56827== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==56827== Command: ./ex6
==56827==
View indexer.rb
=begin
## Description
A tool for Octopress to generate IDs in header tags and index list aside. It helps you easily build a tutorial page with many chapters.
## Features
* Support all languages.
## Syntax
@robertjwhitney
robertjwhitney / tower_of_hanoi.rb
Last active Dec 13, 2015
A lesson in recursion
View tower_of_hanoi.rb
# LETS GET READY TO RECURSE!!!!!!
#
# Tower of Hanoi
#
# You have 4 discs which vary in size from small to large
# There are 3 pegs, A, B, C, respectively
#
# The discs are all currently on peg A, with the largest disc on the bottom,
# and the smallest disc on the top.
#
@robertjwhitney
robertjwhitney / spellcheck.rb
Last active Nov 2, 2016
Use Google's undocumented spellcheck API to make spelling correction suggestions.
View spellcheck.rb
# Unfortunately, Google doesn't return the actual string it is suggesting
# replacements for, so this got a little complicated. Fork and improve!
require 'httparty'
require 'nokogiri'
# > Spellcheck.correct("Ths is a tst")
# => "This is a test"
# > Spellcheck.correct("My nme is Robrt Whtney")
# => "My name is Robert Whitney"
View golf.rb
# Generate the sequence of numbers below.
# 0 1 2 3 4 5 6 7 8 9
# 1 2 3 4 5 6 7 8 9 0
# 2 3 4 5 6 7 8 9 0 1
# 3 4 5 6 7 8 9 0 1 2
# 4 5 6 7 8 9 0 1 2 3
# 5 6 7 8 9 0 1 2 3 4
# 6 7 8 9 0 1 2 3 4 5
# 7 8 9 0 1 2 3 4 5 6
View rake_arguments.rake
desc "a task with arguments"
task :example, :some_arg do |t, args|
# .. do something with the arguments
end
# > rake -T
# > rake example[some_arg] # a task with arguments
@robertjwhitney
robertjwhitney / activeadmin_sortable.js.coffee
Created Jul 3, 2012
Simple drag/drop reordering of records in an ActiveAdmin view table
View activeadmin_sortable.js.coffee
# http://stackoverflow.com/a/8936202
#
# ActiveAdmin already includes the necessary jquery in active_admin/base,
# so just add this to javascripts/active_admin.js after //= require active_admin/base
#
#
# Serialize and Sort
#
# model_name - you guessed it, the name of the model we are calling sort on.
# This is the actual variable name, no need to change it.
@robertjwhitney
robertjwhitney / uri.js
Created May 7, 2012 — forked from jlong/uri.js
URI Parsing with Javascript
View uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"