Skip to content

Instantly share code, notes, and snippets.

View rantler's full-sized avatar

Randy Antler rantler

  • Computer Diversions
  • Seattle, WA
  • 10:22 (UTC -07:00)
View GitHub Profile
@rantler
rantler / foo.rb
Created May 27, 2014 23:50
Read CSV skipping crap at the start of the file
require 'rubygems'
require 'csv'
File.open('/tmp/foo.csv', 'r') do |file|
file.readline # crap
file.readline # krap
csv = CSV.new(file, headers: :first_row).each do |row|
puts row.inspect
end
end
# encoding: utf-8
namespace :db do
desc "Import DB Data"
namespace :import do
desc "Import production db to whatever 'ENV['to']' db is set to and s3 sync"
task :production => :environment do
## example rake db:import:production to=qa s3=true
## or no s3
@rantler
rantler / sum.rb
Last active August 29, 2015 14:17 — forked from davingee/gist:8278b9f6c66f0c53f5e9
Fork of SumOfEach with "equals5" solution
# gem install awesome_print
# gem install benchmark
# gem install pry
require 'awesome_print'
require 'pry'
require 'benchmark'
class SumOfEach
attr_accessor :number_to_equal, :array, :answers, :array_count, :to_remove, :answered
Determine MySQL 5.1 maximum memory usage:
SELECT ( @@key_buffer_size + @@query_cache_size + @@tmp_table_size + @@innodb_buffer_pool_size + @@innodb_additional_mem_pool_size + @@innodb_log_buffer_size + @@max_connections * ( @@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size + @@join_buffer_size + @@binlog_cache_size + @@thread_stack ) ) / 1073741824 AS MAX_MEMORY_GB
From: http://dev.mysql.com/doc/refman/5.0/en/memory-use.html
// 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,
@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',
@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 / 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 / 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: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';