Skip to content

Instantly share code, notes, and snippets.

View tjsingleton's full-sized avatar

TJ Singleton tjsingleton

View GitHub Profile
@tjsingleton
tjsingleton / example_of_dynamic_message.txt
Created November 19, 2010 20:46
Example of a dynamic error message.
ruby-1.9.2-p0 > User.new.save!
ActiveRecord::RecordInvalid: Validation failed: Email is too short (minimum is 6 characters), Email should look like an email address., Email is too short (minimum is 3 characters), Email should use only letters, numbers, spaces, and .-_@ please., Password is too short (minimum is 4 characters), Password confirmation is too short (minimum is 4 characters), First name can't be blank, Last name can't be blank, Company name can't be blank, User type is not included in the list, Company size is not included in the list, Industry is not included in the list
@tjsingleton
tjsingleton / require_timer.rb
Created November 23, 2010 17:32
Provides the timing for each required file.
module RequireTimer
attr_reader :load_times
def self.extended(base)
base.instance_variable_set :@load_times, {}
end
def require(*items)
items.each do |item|
start = Time.now
@tjsingleton
tjsingleton / extract_date_from_php_serialization.sql
Created December 2, 2010 22:08
I'm too lazy to rewrite this plugin. How messed up is this!? Extracting date from a php serialized value.
SELECT * FROM wp_postmeta
WHERE wp_postmeta.meta_key = "_MyEvent"
AND STR_TO_DATE(SUBSTR(meta_value, LOCATE('dateStart";s:10:"', meta_value)+17, 10), "%d/%m/%Y") < NOW();
class Rainbows
# (¯`•.•´¯) (¯`•.•´¯) BEST METHOD
# *`•.¸(¯`•.•´¯)¸.•´ ♥ EVA!
# ☆ º ♥ `•.¸.•´ ♥ º ☆.¸¸.•´¯`♥
def shine
end
end
<?php // BRAD
$numbers = array("1", "2", "3", "4", "5");
function array_print($values) {
$array = array_reverse($values);
print_values($array);
}
function print_values($array) {
echo array_pop($array);
[~]$ zsh_stats rvm:ruby-1.9.2-p136
334 cd
248 git
223 ls
126 exit
125 gitx
116 rake
112 mate
86 node
77 clear
@tjsingleton
tjsingleton / history_stats.rb
Created February 10, 2011 03:21
zsh_stats clone. Usage: history | ruby history_stats.rb
#!/usr/bin/env ruby
require 'optparse'
PADDING = 1
options = {
:input => $stdin,
:limit => 10
}
[master][~/Projects/crunch/rails]$ jobs rvm:ruby-1.9.2-p136@crunch
[1] running rake jobs:work &> /dev/null
[2] running rake unicorn &> /dev/null
[3] - running coffee -w -c -l -o build/ src/
[4] + running node build/echo.js &> node.log
@tjsingleton
tjsingleton / deskshare_standalone.js
Created February 23, 2011 15:51
uses http://code.google.com/p/swfobject/ to embed bbb's deskshare standalone viewer.
var HOSTNAME: 'localhost'
, SHARE_SWF: '/client/DeskshareStandalone.swf'
, INSTALL_SWF: '/expressInstall.swf'
, ARCHIVE: "/client/bbb-deskshare-applet-0.71.jar"
, CODE: "org.bigbluebutton.deskshare.client.DeskShareApplet.class"
, SWF_ID: "screen_viewer"
, VIEWER_WIDTH: 800
, VIEWER_HEIGHT: 600
, ROOM_NUMBER: 1;
fizzbuzz = {3 => 'Fizz', 5 => 'Buzz', 15 => 'FizzBuzz'}
range = (1..100)
replacements = Hash.new {|key, value| value }
fizzbuzz.each do |i, replacement|
range.each_slice(i) {|i| replacements[i.last] = replacement }
end
range.each {|i| puts replacements[i] }