This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'action_controller' | |
class Sanitizer | |
def initialize(model) | |
@delegate = model | |
end | |
def method_missing(method_name, *args, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
OlderNewer