Skip to content

Instantly share code, notes, and snippets.

View prathe's full-sized avatar

Philippe Rathé prathe

  • Remote, North America
View GitHub Profile
Feature: User login
Scenario: User is greeted upon login
Given a user with an account
When he logs in
Then he should be greeted
@prathe
prathe / gist:1398482
Created November 27, 2011 23:50
Managing websites locally with POW

Disable Web sharing

In System Prefecences under Sharing, uncheck "Web Sharing". You probably won't need it anymore.

Update to the latest XCode

Install MySQL with homebrew

brew update
brew install mysql
@prathe
prathe / gist:1628799
Created January 17, 2012 20:51
BigDecimal#to_s without trailing zero
class BigDecimal
def to_s(s = 'F')
sign, significant_digits, base, exponent = self.split
if self.zero?
'0'
elsif significant_digits.size <= exponent
self.to_i.to_s
else
self.to_f.to_s
end
state_machine :state, initial: :opened do
state :opened
state :confirmed
state :rejected
state :closed
event :confirm_it do
# only user
transition [:opened, :rejected] => :confirmed
<%= form_for @timesheet, :builder => TimesheetFormBuilder do |timesheet_form| %>
<%= timesheet_form.fields_for :worklogs do |worklog_form| %>
<%= worklog_form.text_field :monday %>
<% end %>
<% end %>
@prathe
prathe / gist:1910116
Created February 25, 2012 19:06
Installing gcc from sources on OSX
# Grab and unpack the tarball
$ mkdir -p ~/src && cd ~/src
$ curl -O http://opensource.apple.com/tarballs/gcc/gcc-5666.3.tar.gz
$ tar zxf gcc-5666.3.tar.gz
$ cd gcc-5666.3
# Setup some stuff it requires
$ mkdir -p build/obj build/dst build/sym
# And then build it. You should go make a cup of tea or five whilst this runs.
$ sudo gnumake install RC_OS=macos RC_ARCHS='i386 x86_64' TARGETS='i386 x86_64' \
@prathe
prathe / Highlights-on-REST.markdown
Created March 3, 2012 02:17
Highlights on REST

Highlights on REST

By Roy Fielding himself

Quotes have been taken from Roy Fielding's blog posts writings and own comments.

A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types. Any effort spent describing what methods to use on what URIs of interest should be entirely defined within the scope of the processing rules for a media type (and, in most cases, already defined by existing media types). [Failure here implies that out-of-band information is driving interaction instead of hypertext.]

Subjects that Steve Klabnik could cover in his new book:
Taken from Fielding's dissertation
> As a result, cookie-based applications on the Web will never be reliable.
> The same functionality should have been accomplished via anonymous authentication and true client-side state.

Linus Torvalds about license

So when I try to explain my choice of license, I use the term ‘Open Source’, and try to explain my choice of the GPLv2 not in terms of freedom, but in terms of how I want people to be able to improve on the source code - by discouraging hiding and controlling of the source code with a legal copyright license

GPLv2 is there to keep it from anarchy: it doesn't block competition and people working at opposite ends, but it does block people from trying to be anti-social and hurt each other.

@prathe
prathe / gist:2439752
Created April 21, 2012 21:33
Python Regular Expression: double-quoted string literals that allows for escaped double quotes
# Tricky REs with ^ and \
# Assign to regexp a regular expression for double-quoted string literals that
# allows for escaped double quotes.
# Hint: Escape " and \
# Hint: (?: (?: ) )
import re