Skip to content

Instantly share code, notes, and snippets.

# http://challenge.greplin.com/
# author: Thomas Shaddox
# twitter @baddox
# facebook.com/tshaddox
# tshaddox.com
def one():
s = "Fourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanew\
nationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreated\
equalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartio\
@tshddx
tshddx / gist:1068361
Created July 6, 2011 21:24
Rails. Render a layout outside a controller, with text and locals
av = ActionView::Base.new(Rails::Configuration.new.view_path)
av.render(
{:text => this_goes_to_yield, :layout => "layouts/blah.html.erb"}, # the options hash
{:title => 'blah', :body => 'hello'} # the locals hash
)
@tshddx
tshddx / mp3_organize.rb
Created January 24, 2012 08:34
Sick of messing with crappy MP3 renaming/tagging/reorganizing tools for such a simple task.
require 'find'
require 'mp3info'
class ArtistsHash < Hash
def initialize
super
self.default_proc = proc do |h, artist_name|
h[artist_name] = AlbumsHash.new
end
end
@tshddx
tshddx / Birthday Collisions.rb
Created March 28, 2012 23:42
What are the odds of, in a set of X people, there being at least Y people who share a birthday?
# Thomas Shaddox
# https://github.com/baddox
# Assumes birthdays are independent (i.e. uniformly distributed)
days = 365
ppl = 290 # I'm so popular
trials = 10_000
at_least_four = 0
trials.times do
array = [0] * days
@tshddx
tshddx / json.rb
Created October 30, 2012 22:40
proposed json format
{
:stream => [
{
:user => external_hash, # perhaps some sort of partial or ad hoc hash
:type => "leaderboard|challenge",
# slightly counterintuitively, challenge will always be present
# even if type is leaderboard
@tshddx
tshddx / make_github_pull_request_commit_and_blob_pages_full_width_with_the_touch_of_a_button.user.js
Last active July 24, 2017 15:07
Make GitHub Pull Request, Commit, and Blob pages full width with the touch of a button
// ==UserScript==
// @name make github pull request commit and blob pages full width with the touch of a button
// @namespace https://gist.github.com/baddox/8739362
// @description Makes the GitHub Pull Request, Commit, and Blob pages span the full width of the browser, rather than maxing out at the default ~900 pixels.
// @include https://github.com/*
// @grant none
// @version 1.1
// ==/UserScript==
var html = '<span class="go-full-width" style="font-size:18px; padding:6px; background-color:silver; opacity:0.6; cursor:pointer; position:fixed; bottom:10px; left:10px;">Full width</span>';
@tshddx
tshddx / ruby heredoc
Created May 8, 2014 01:58
ruby heredoc
irb(main):010:0> puts(<<X, <<Y)
irb(main):011:1" this is x
irb(main):012:1" X
irb(main):013:1" this is y
irb(main):014:1" Y
this is x
this is y
=> nil
@tshddx
tshddx / lol.rb
Created June 2, 2014 23:34
Some Ruby lols
a = [1,2,3]
# => [1, 2, 3]
enum = a.map!
# => #<Enumerator: [1, 2, 3]:map!>
enum.map(&:to_s)
# => ["1", "2", "3"]
a
### Keybase proof
I hereby claim:
* I am baddox on github.
* I am shaddox (https://keybase.io/shaddox) on keybase.
* I have a public key whose fingerprint is 326A 3C60 FFEE 147E 9611 6560 413A 661B 220C B38D
To claim this, I am signing this object:
@tshddx
tshddx / kippt_to_pinboard.rb
Last active August 29, 2015 14:04
Pull bookmarks from Kippt API, upload via Pinboard API
# Instructions
# install required packages by running:
# gem install json typhoeus awesome_print
# Download this .rb into a new directory on your PC (called something like "pinboard" or whatever)
# Fill out KIPPT_USERNAME, KIPPT_API_TOKEN, and PINBOARD_AUTH_TOKEN (below) by changing xxx to the real value.
# Run the script by running