Skip to content

Instantly share code, notes, and snippets.

@mattknox
mattknox / humanize.rb
Created May 3, 2011
Numeric#humanize makes numbers more readable.
View humanize.rb
class Numeric
SCALE_TO_WORD = Hash.new do |h, i|
" * 10^#{i * 3}"
end.merge({ 1 => " thousand",
2 => " million",
3 => " billion",
4 => " trillion"
})
# in my unscientific test, no one really found names beyond trillion useful.
@ryanking
ryanking / gist:954555
Created May 4, 2011
Selectively stop classes from being modified in ruby.
View gist:954555
# Ever get tired of people messing with your ruby classes?
# now you can put the hammer down and stop them. Just
# include this module and no one will be able to modify the
# class implementation or any instance implementations.
module Stop
module CantTouchThis
def self.included(mod)
@joshwand
joshwand / gist:1145669
Created Aug 15, 2011
Blocking the new version of the NYTimes paywall
View gist:1145669

The NYTimes has updated their paywall-- it's slightly more sophisticated. The content is no longer hidden behind a big transparent div, but instead is now actually removed from the page entirely. It's still simple to defeat, though. Using adblock plus (or your preferred adblocking device), block the following URLs:

*://*.nytimes.com/*/gwy.js*
*://*.nytimes.com/*/gw.js*

And you're done.

@tokudu
tokudu / ec2ssh.sh
Created Oct 27, 2012
A helper script for SSH'ing into EC2 instances by name
View ec2ssh.sh
#!/bin/bash
# SSH into an EC2 instance by name
# Author: tokudu@github.com (SoThree.com).
set -e
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` instance_name"
exit 1
fi
@dpetersen
dpetersen / circle.yml.diff
Created Mar 11, 2015
CircleCI junit integration
View circle.yml.diff
commit 744cfc17ad795077a427b19d02c10e4f0b5008b7
Author: Don Petersen <don@donpetersen.net>
Date: Tue Mar 10 15:43:22 2015 -0600
Include circle-compatible test output.
diff --git a/circle.yml b/circle.yml
index a2763cf..ece9b30 100644
--- a/circle.yml
+++ b/circle.yml
View pd_maintenance_windows.rb
#!/usr/bin/env ruby
# Ruby script to create recurring maintenance windows in PagerDuty
#
# Copyright (c) 2012, PagerDuty, Inc. <info@pagerduty.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
@deenseth
deenseth / gist:1514633
Created Dec 23, 2011
Add Google Calendar Event Bookmarklet
View gist:1514633
javascript: var s;
/*Figure out the selected text*/
if ( window.getSelection ) {
s = window.getSelection();
} else if ( document.getSelection ) {
s = document.getSelection();
} else {
s = document.selection.createRange().text;
}
/*If there isn't any text selected, get user input*/
@tehprofessor
tehprofessor / watir_phantomjs_user_agent_settings.rb
Created May 1, 2013
Configuring Watir to use a custom user agent with the PhantomJS driver. The user agent gem has been deprecated, and this functionality is not documented anywhere (obvious).
View watir_phantomjs_user_agent_settings.rb
require 'watir-webdriver'
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
browser = ::Watir::Browser.new driver
# Quick test to make sure it's set
browser.goto 'http://www.useragentstring.com/'
browser.textarea(:id => "uas_textfeld").value
@tribut
tribut / mosh_pc.sh
Last active Jun 4, 2018
wrapper for mosh to work with ssh's proxycommand directive. this only makes sense if the target machine is directly reachable from the internet using udp (but probably not via tcp). usage: mosh_pc.sh [host as mentioned in .ssh/config] [public ip of host]
View mosh_pc.sh
#!/bin/sh
# ########################################################## #
# wrapper for mosh to work with ssh's proxycommand directive #
# this only makes sense if the machine is directly reachable #
# from the internet using udp. #
# ########################################################## #
THISSCRIPT="`basename \"$0\"`"
REMOTE="$1"
@cuibonobo
cuibonobo / \boot\cmdline.txt
Created May 30, 2013
To use bootchart on the Raspberry Pi, `sudo apt-get install bootchart bootchart-view` and then add `init=/sbin/bootchartd` to the end of `/boot/cmdline.txt`
View \boot\cmdline.txt
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=120,data=writeback elevator=deadline rootwait quiet init=/sbin/bootchartd