Skip to content

Instantly share code, notes, and snippets.

View rantler's full-sized avatar

Randy Antler rantler

  • Computer Diversions
  • Seattle, WA
  • 15:41 (UTC -07:00)
View GitHub Profile
@account = Account.find(131856)
@account.set_shard_connection
@agent = Agent.find(3256655)
@metric = Metric.find(425412176)
time_window = TimeWindow.new((Time.now.utc - 1.day).to_i, Time.now.utc.to_i)
@timeslice_data = Timeslice.find_and_aggregate(@agent, time_window, @metric, :aggregate_time => false, :raw_data => true)
class PluginRater
def self.rate_plugin_for_user!(rating, plugin, user)
plugin.update_rating_for_user(rating, user)
Event::Publish('user_rated_a_plugin', rating, plugin, user)
Auditor::AuditRatingChange(rating, plugin, user)
end
end
class Controller
def rate
@rantler
rantler / gist:7309428
Last active December 27, 2015 10:09
Software Developer Interview Questions

(See also https://gist.github.com/ryansobol/5252653)

Originally published November, 2013

Javascript

How would you toggle the visibility of several controls on the page?

$$('#element_one, #element_two').invoke('toggle');

@rantler
rantler / gist:7034159
Created October 17, 2013 23:32
Fib(111111)
2,993,717,480,458,674,908,733,078,505,849,100,877,784,752,474,407,970,784,777,982,933,032,299,915,607,456,584,350,734,288,199,678,298,057,023,547,642,133,556,459,842,823,351,420,653,618,908,442,506,537,140,874,134,893,915,505,096,701,911,979,338,787,150,902,113,486,096,257,549,453,567,977,276,240,859,580,715,880,702,555,252,519,755,283,622,058,711,130,731,562,563,655,168,973,134,991,636,342,197,801,286,507,632,401,926,438,563,655,774,906,335,864,864,729,631,435,236,236,885,265,125,253,670,491,304,479,125,680,108,355,901,460,171,287,676,228,271,996,252,773,804,148,484,642,055,975,821,970,723,516,015,443,684,594,081,463,096,144,340,164,057,879,356,756,905,407,109,073,831,170,044,988,227,625,453,876,690,315,656,028,773,968,024,095,524,544,976,927,649,755,127,879,197,475,409,648,681,614,334,126,614,821,881,068,020,553,186,391,548,578,611,585,309,801,614,924,252,989,099,133,585,387,299,164,548,525,283,947,288,600,473,501,542,171,178,617,483,491,020,538,707,291,098,842,580,189,556,070,638,510,815,419,264,004,657,26
@rantler
rantler / gist:6409234
Created September 2, 2013 04:34
JavaScript two-dimensional array example
var size = 3;
var grid = new Array(size);
for (var i = 0; i < size; i++) {
grid[i] = new Array(size);
}
grid[0][0] = 'x';
grid[0][1] = 'o';
grid[0][2] = 'o';
@rantler
rantler / re-install libxml2
Created August 30, 2013 21:24
Fixes "Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0"
brew install libxml2 libxslt
brew link --force libxml2 libxslt
cd /tmp
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
make
sudo make install
@rantler
rantler / gist:5853394
Last active December 18, 2015 22:18
Sanitizing Decorator
require 'rubygems'
require 'action_controller'
class Sanitizer
def initialize(model)
@delegate = model
end
def method_missing(method_name, *args, &block)
@rantler
rantler / gist:5853156
Created June 24, 2013 20:08
Freedom patch!
require 'rubygems'
require 'action_controller'
class String
unless respond_to?(:sanitized)
define_method :sanitized do
ActionController::Base.helpers.sanitize(
self || 'No name',
:tags => %w(h3 h4 ul ol li p a strong em br font),
@rantler
rantler / sanitilolize
Last active December 18, 2015 17:39
Hilariously over-engineered sanitization module
require 'rubygems'
require 'action_controller'
module Sanitizer
def method_missing(method_name, *)
attr = sanitized_attr_method_name(method_name)
if attr && respond_to?(attr)
ActionController::Base.helpers.sanitize(
send(attr) || 'No name',
// Counting Event observers with Prototype 1.6
javascript:alert(
"Event Observers\n" + $H(Event.cache).inject( $H(),
function (acc, p) {
$H(p.value).each(
function (evtT) {
if ( !acc.get(evtT.key) )
acc.set(evtT.key, 0);
acc.set(evtT.key,