Skip to content

Instantly share code, notes, and snippets.

@EricLondon
EricLondon / gist:2050793
Created March 16, 2012 16:15
Programmatically create paperclip attachment
1.9.2-p290 :002 > u = Upload.new
=> #<Upload id: nil, post_id: nil, created_at: nil, updated_at: nil, upload_file_name: nil, upload_content_type: nil, upload_file_size: nil, upload_updated_at: nil>
1.9.2-p290 :004 > u.upload = File.open('/Users/Eric/Desktop/estimation grid.png')
=> #<File:/Users/Eric/Desktop/estimation grid.png>
1.9.2-p290 :005 > u.save!
(0.1ms) begin transaction
SQL (17.4ms) INSERT INTO "uploads" ("created_at", "post_id", "updated_at", "upload_content_type", "upload_file_name", "upload_file_size", "upload_updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 16 Mar 2012 16:13:46 UTC +00:00], ["post_id", nil], ["updated_at", Fri, 16 Mar 2012 16:13:46 UTC +00:00], ["upload_content_type", "image/png"], ["upload_file_name", "estimation_grid.png"], ["upload_file_size", 53079], ["upload_updated_at", Fri, 16 Mar 2012 16:13:43 UTC +00:00]]
(23.8ms) commit transaction
@EricLondon
EricLondon / gist:2148743
Created March 21, 2012 15:45
ruby screen shot
#!/usr/bin/env ruby
require 'selenium-webdriver'
require 'uri'
website_url = ARGV[0]
if website_url.empty?
puts "Website Argument Required.\n"
exit()
end
@EricLondon
EricLondon / .gitconfig
Last active June 6, 2016 11:14
~/.gitconfig
[user]
name = Eric London
email = [email protected]
[core]
excludesfile = /Users/Eric/.gitignore
[alias]
lg = log --graph --pretty=format:'%C(red)%h%Creset%C(yellow)%d%Creset %C(bold blue)%an%Creset %C(green)%cr%Creset %s' --abbrev-commit --date=relative --all
lg2 = log --graph --pretty=format:'%C(red)%h%Creset%C(yellow)%d%Creset %C(bold blue)%an%Creset %C(green)%cr%Creset %s' --abbrev-commit --date=relative
[color]
ui = auto
@EricLondon
EricLondon / index.md
Created September 26, 2012 17:11 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

framework 'AppKit'
class Download
attr_reader :response, :responseBody
def start(request)
puts "START!"
NSURLConnection.connectionWithRequest(request, delegate:self)
end
@EricLondon
EricLondon / gist:72952b77499badad4e29
Last active August 29, 2015 14:06
Rails Model Concern: track which classes have included the Concern
require 'active_support/concern'
module ChildTrackable
extend ActiveSupport::Concern
# keep track of what classes have included this concern:
module Children
extend self
@included_in ||= []
@EricLondon
EricLondon / gist:df145895d5a3bacd2f7e
Last active August 29, 2015 14:23
IMS nginx & passenger
# I had nginx and passenger already installed via brew:
# note: this caused problems with RVM & gemsets
brew uninstall nginx passenger
brew cleanup
##########
# from the IMS rails project:
# note/todo: add to Gemfile?
gem install passenger -v 5.0.10
@EricLondon
EricLondon / gist:f5e4722c15d1e9d6a7d1
Created July 9, 2015 12:51
nodejs spawn shell process (ps aux) and filter
var run_cmd = function(cmd, args, callBack) {
var spawn = require('child_process').spawn;
var child = spawn(cmd, args);
var resp = "";
child.stdout.on('data', function (buffer) { resp += buffer.toString() });
child.stdout.on('end', function() { callBack (resp) });
}
var check_ps_aux = function(service) {
@EricLondon
EricLondon / gist:a3f1297cf8bc63673c79
Created July 14, 2015 20:06
RSpec Capybara Poltergeist config
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {
debug: true,
timeout: 120,
js_errors: true,
inspector: true,
phantomjs_options: ['--load-images=no', '--ignore-ssl-errors=yes'],
@EricLondon
EricLondon / emoji.rb
Created October 30, 2015 15:03 — forked from everm1nd/emoji.rb
Print Emoji in Ruby
# all emoji
# 1000.times { |i| emoji(127740 + i) + ' ' }
# moon phases
# 8.times { |i| emoji(127761 + i) }
DELAY = 0.3;
# clean screen
def clean