Skip to content

Instantly share code, notes, and snippets.

@nyarly
nyarly / fibanocci.rb
Created September 13, 2012 19:36
Enumerable Examples
class Fibonacci
include Enumerable
def initialize
@this = 1
@next = 1
end
@nyarly
nyarly / meta-state.rb
Created December 3, 2012 20:49
Module + metaprogramming based FSM in Ruby
module MetaState
class Error < ::StandardError; end
class WrongStateError < Error; end
class InvalidStateError < Error; end
class Machine
NON_MESSAGES = [:on_exit, :on_enter]
class << self
def add_state(state)
@nyarly
nyarly / Proposal
Created February 2, 2013 22:39
A Rubygems trust proposal
Here's the basic premises: invent as little cryptography as you can. Make the tools as simple as possible.
Here's the proposal: use PGP for agent authentication, use git for verification distribution.
The kernel of the idea is this: in a public git repo, any user can create file(s) that are a list of tuples of the form:
{domain,object identifier,public identity,signature}
When I release a gem, I sign it, and add
rubygems mygem-x.y.z [email protected] {signature}
#!/bin/bash
for branch in $(git branch --merged | egrep -v '(master)|(staging)|(production)'); do
echo Cleaning: $branch
#If we can delete the branch remotely, delete it locally
git push origin :$branch && git branch -d $branch
done
#!/bin/sh
BUNDLE_BASE=~/ruby/bundle-paths/rails3
if [ -f .bundle/config ]; then
echo "Bundle config file already exists"
bundle install
else
projname=$(basename $(pwd))
BUNDLE_PATH="$BUNDLE_BASE/lib"
export PROMPT_DIRTRIM=2
if [[ ! $PROMPT_COMMAND =~ __bundler_prompt_command ]]; then
export PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; __bundler_prompt_command"
fi
# Put your fun stuff here.
PS1='\[\033[01;31m\]$(__bundler_ps1)\[\033[00;34m\]\[\033[32m\]\u@\h\[\033[34m\] \w\[\033[01;32m\]$(__git_ps1) \[\033[34m\]\$\[\033[00m\] '
@nyarly
nyarly / utils.rb
Last active December 13, 2015 19:38
def align(string)
lines = string.split(/\n/)
first = lines.shift
match = /^(\s*)<<</.match(first)
unless(match.nil?)
return lines.map do |line|
unless /^#{match[1]}|^\s*$/ =~ line
raise Errors::UnderIndented, line
end
line.sub(/^#{match[1]}/, "")
@nyarly
nyarly / fu.rb
Last active December 14, 2015 03:38
class Uuu < RSpec::Core::Formatters::ProgressFormatter
def example_passed(example)
if @failed_examples.empty?
super
else
output.print red("u")
end
end
end
<p>I've recently gotten really excited about REST (or Hypermedia APIs) and about RDF. Here's a quick trail of breadcrumbs about why. Come be excited.</p>
<A HREF="http://vimeo.com/20781278" >Hypermedia APIs - Jon Moore on Vimeo</A>
<A HREF="https://gist.github.com/jonm/1445773" >Shallow vs. deep representations in XHTML Hypermedia APIs</A>
<A HREF="http://www.w3.org/TR/2011/WD-microdata-20110405/" >HTML Microdata</A>
<A HREF="http://markmail.org/message/mlf5fmvtkvaxa7co" >Re: [whatwg] Proposal to extend Microdata API specification - Ian Hickson - org.whatwg.lists.whatwg - MarkMail</A>
<A HREF="http://manu.sporny.org/2012/mythical-differences/" >Mythical Differences: RDFa Lite vs. Microdata | The Beautiful, Tormented Machine</A>
<A HREF="http://www.w3.org/TR/rdfa-lite/" >RDFa Lite 1.1</A>
rspec ./spec/controllers/demo_impressions_controller_spec.rb:84 # DemoImpressionsController when a demo PG ad with offers is requested should render a PG ad that has offers
rspec ./spec/controllers/impressions_controller_spec.rb:137 # ImpressionsController with successful ad fetch with PG offer ads should render it's views and should load successfully
rspec ./spec/jobs/ad_cache_page_spec.rb:17 # AdCachePage should find appropriate Pricegrabber ads for page
rspec ./spec/jobs/refresh_page_spec.rb:28 # RefreshPage on a finished page should not raise error
rspec ./spec/jobs/refresh_page_spec.rb:34 # RefreshPage on a finished page should enqueue next job
rspec ./spec/jobs/refresh_page_spec.rb:40 # RefreshPage on a finished page should reset AdCachePage
rspec ./spec/jobs/refresh_page_spec.rb:47 # RefreshPage on a finished page should reset FinishPage
rspec ./spec/lib/ad_engine/ad_finder_spec.rb:228 # AdEngine::AdFinder get ads with no ilk given with a query should return ads of both pg and groupon
rspec ./spec/lib/