Skip to content

Instantly share code, notes, and snippets.

View addamh's full-sized avatar

Addam Hardy addamh

View GitHub Profile
The Ten Commandments of Egoless Programming
Appropriate, even if old…I’ve seen it referenced as coming from The Psychology of Computer Programming, written in 1971, but I don’t actually see it in the text. Regardless, here are The Ten Commandments of Egoless Programming, found on @wyattdanger‘s blog post on receiving advice from his dad:
Understand and accept that you will make mistakes. The point is to find them early, before they make it into production. Fortunately, except for the few of us developing rocket guidance software at JPL, mistakes are rarely fatal in our industry. We can, and should, learn, laugh, and move on.
You are not your code. Remember that the entire point of a review is to find problems, and problems will be found. Don’t take it personally when one is uncovered. (Allspaw note – related: see below, number #10, and the points Theo made above.)
No matter how much “karate” you know, someone else will always know more. Such an individual can teach you some new moves if you ask. Seek and ac
console.log ['fizz' unless i % 3] + ['buzz' unless i % 5] or i for i in [1..100]
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
def santize_quantity input
if input.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
if input =~ /\d\.0$/
key = v["name"].to_i
else
denominator = input.to_s.match(/\.(\d+$)/).captures.first
numerator = input.to_s.match(/^(\d*)./).captures.first
fraction = "0.#{denominator}".to_f.rationalize(0.01).to_s
key = "#{numerator} #{fraction}"
end
@addamh
addamh / gist:5675663
Created May 30, 2013 04:08
linkedin gem search
irb(main):008:0> fields = [{:people => [:id, :first_name, :last_name, "picture-url"]}, :num_results]
=> [{:people=>[:id, :first_name, :last_name, "picture-url"]}, :num_results]
irb(main):009:0> u.to_linkedin_client.client.search(:keywords => 'Josephine', :facet => ["network,F"], :fields => fields)
=> #<LinkedIn::Mash people=#<LinkedIn::Mash all=[#<LinkedIn::Mash first_name="Josephine" id="l07zWYkuXf" last_name="Mangani" picture_url="http://m3.licdn.com/mpr/mprx/0_VoW0f8w6JUgAo3qXNaJ8fiEWUVVTokqX4Ig8fisMkJalzhikn2M1T_aBvtsYW_zHRdw3hkeGAfgf">] total=1> total_results=1>
irb(main):010:0>
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = Motion::Xray::XrayWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(TwitterViewController.alloc.initWithStyle(UITableViewStylePlain))
@window.makeKeyAndVisible
true
end
end

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
- flash.each do |key, msg|
%div{:class => "alert alert-#{key}"}
%h4= msg
class ServicesController < ApplicationController
before_filter :authenticate_user!, :except => [:create, :signin, :signup, :newaccount, :failure]
protect_from_forgery :except => :create
# GET all authentication services assigned to the current user
def index
@services = current_user.services.order('provider asc')
end
# POST to remove an authentication service
!!!
%html
%head
%title Btiques
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tag
%body#pre-auth
%body
- flash.each do |key, msg|