Skip to content

Instantly share code, notes, and snippets.

@robertjwhitney
robertjwhitney / film.rb
Created April 22, 2012 23:45
Conditionally display an image instead of the file input in an ActiveAdmin has_many association.
# active_admin and formtastic seem kinda picky about displaying both the
# image and the file input together here... in fact, it seems like this
# is the ONLY way to do this? Adding anything else after the image_tag squashes it.
ActiveAdmin.register Film do
form do |f|
f.inputs "Film" do
f.input :title
end
f.has_many :stills do |film_still_form|
@robertjwhitney
robertjwhitney / chat.rb
Created April 1, 2012 17:29 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
node> if ([]) { console.log ("hey"); }
hey
node> [] == false
true
node> [] == true
false
node> if (false) { console.log("hey"); }
@robertjwhitney
robertjwhitney / photo.rb
Created March 24, 2012 18:59
How to access the dimensions of an image in the view using carrierwave and mini_magick
class Photo < ActiveRecord::Base
mount_uploader :file, StillImageUploader
def dimensions(version = nil)
image ||= MiniMagick::Image.open(file.url(version))
{width: image['width'], height: image['height']}
end
end
# photo.dimensions
let g:NERDTreeMouseMode = 3
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
@robertjwhitney
robertjwhitney / loadHtml.coffee
Created March 15, 2012 19:47
well that was silly
loadHtml = (elem, url) ->
$.ajax
url: url
context: document.body
dataType: "html"
success: (data) ->
elem.html data
@robertjwhitney
robertjwhitney / gmail_filter.txt
Created March 7, 2012 20:37
Awful Recruiters
*@workbridgeassociates.com OR *@vtrit.com OR *@jsgeeks.com OR *@questgroups.com OR *@identified.com OR *@sysdevit.com OR *@kbretz.com OR *@brightonsearchgroup.com OR *@trajectory.us.com OR *@peakrecruit.com OR *@turner.com OR *@surrex.com OR *@strategic-staffing.com OR *@encoress.com OR *@kforce.com OR *@epro-consulting.com OR *@resourcis.com OR *@bravotech.com OR *@aplussearch.com OR *@kutirtech.com OR *@thebackplane.com OR *@sptechpartners.com OR *@aimconsulting.com OR *@jobspringpartners.com OR *@axiustek.com OR *@lumoslabs.com OR *@rivierapartners.com OR *@omegasolutioninc.com OR *@good.com OR *@marlabs.com OR *@silversearchinc.com OR *@ownpointofsale.com OR *@talent4now.com OR *@githire.com OR *@linkedin.com OR *@clearslide.com OR *@xcreek.com OR *@disys.com OR *@jinibot.com OR *@avanitechsolutions.com
@robertjwhitney
robertjwhitney / digits.rb
Created January 25, 2012 04:05
get de digits
#http://thehackerolympics.com/
key = 'qwertyuiop'
string = 'iirytroyppytpeppowuiyoiuypipiyuyotyoiwiytorouqyiepyirueuiprpptwyiroqwtuyipourrrourorwipowiorutpwtwruuioquteorioriyutwqyyprptuqqquuituyywyuoewtrppqwrtiiruirpwyptpuoyyoeyerpqiotuieripurouwuwyuwrworowitoepoypeipeypiireeorrwripuuteoitpuutturruwiyryeetyrioweytueqrrrtotrpiqetoyepoipiwrwpppiritupwipruooiepoweypiuwrqywuuwyiroqpqpruioopuiuerputpwwuuiqwpiroewrtwiqerteoyeqtutwoeoipioiuqiiiouuoqtuuwtuwiiqwppqitywuqpuutrqiyoeuuutwrwtoqrqyoeyoiporuuioiwryoeruypreprqroiyuqwtuyoytoerwqryeeripryieypiwqirtriurueypiuyuypriuiwptywppupoioyrewooytreteeriiwroietuwypieeeeeqpiiiwrirtppoeyiwpooyyporpruwuoriiyowuytiwpwpryeywotoyirqypyypoeptiuwwoyprquoetepptorwiewprpiywwtuieeiweytrrwiqtwotioryoiptyyyuriiqiyroeeiqepwteuwptpruuypipieuoiiuuweeuryuuowporrooyywyyrryriqyirooitirueruptotpryoqtipippyptiurwyiryooywtryyuurtrutwqiqiiiqwouyeooueoturuowiuwrtruwwiupwopwweoo'
#split into unique pairs
array = string.scan(/../)
unique_pairs = array.keep_if {|letters| array.count(letters) == 1}
@robertjwhitney
robertjwhitney / stupid-watcher.gemspec
Created December 22, 2011 23:24
stupid watcher is stupid
Gem::Specification.new do |s|
s.name = 'stupid-watcher'
s.version = '0.0.2'
s.platform = Gem::Platform::RUBY
s.author = 'Robert Whitney'
s.email = 'robertj.whitney@gmail.com'
s.summary = 'Stupid watcher is stupid'
s.description = 'Watches a file, does stuff when that file is updated.'
s.files = ['stupid_watcher.rb']
@robertjwhitney
robertjwhitney / heroku_deploy.rake
Created December 13, 2011 15:44 — forked from michaeldwan/heroku_deploy.rake
Simple Rake task for customizing deployment to Heroku
# rake deploy:production master
# List of environments and their heroku git remotes
ENVIRONMENTS = {
:staging => 'myapp-staging',
:production => 'myapp-production'
}
namespace :deploy do
ENVIRONMENTS.keys.each do |env|