Skip to content

Instantly share code, notes, and snippets.

@EricLondon
EricLondon / ubuntu_rials_server_install
Created March 8, 2012 19:51
Ubuntu Rails Server Install
# update installed packages
sudo apt-get update
sudo apt-get upgrade
# ssh server
sudo apt-get install openssh-server -y
# install curl
sudo apt-get install curl -y
@EricLondon
EricLondon / gist:2050420
Created March 16, 2012 14:54
Drupal to Rails JSON parsing script
# loop through nodes:story data
json_data['nodes']['story'].each do |i, story|
##################################################
# modify html per google prettify
# scan for <code> tags
matches = story['body'].scan(/(<code>)(.*?)(<\/code>)/im)
matches.each do |match|
new_string = '<pre class="prettyprint"><code class="prettyprint">' + match[1].gsub(/<\?php/, '&lt;?php') + '</code></pre>'
@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:2111910
Created March 19, 2012 13:22
Rails route that works with: http://localhost:3000/posts/tag/Drupal%205.x
# I created a Post controller to accept a parameter for tag name.
# The problem is, the tag "Drupal 6.x", or anything with a period was triggering :format
get 'posts/tag/:tag' => 'posts#tag', :format => false, :constraints => {:tag => /.*/}
@EricLondon
EricLondon / gist:2126811
Created March 19, 2012 20:28
Random Tree Token Generator
# Usage:
# tree = RandomTreeToken.new
# puts tree.generate
class RandomTreeToken
def initialize
require 'net/http'
url = 'http://treesofnorthamerica.net/'
body = Net::HTTP.get_response(URI.parse(url)).body
@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 = git@ericlondon.com
[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 / gist:3341909
Created August 13, 2012 15:33
BBB Parser
require 'nokogiri'
require 'open-uri'
require 'pp'
url = "http://www.bedbathandbeyond.com/product.asp?sku=40354439&"
doc = Nokogiri::HTML(open(url))
data = {}
@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