Skip to content

Instantly share code, notes, and snippets.

namespace :spec do
# largely lifted from http://www.pervasivecode.com/blog/2007/06/28/hacking-rakestats-to-get-gross-loc/
task :stats_setup do
require 'code_statistics'
class CodeStatistics
alias calculate_statistics_orig calculate_statistics
def calculate_statistics
@pairs.inject({}) do |stats, pair|
if 3 == pair.size
@jnunemaker
jnunemaker / gist:217362
Created October 24, 2009 04:07 — forked from lukesutton/gist:107966
example of warden with sinatra
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
#!/usr/local/bin/macruby
# This example is done with MacRuby and the UIKit framework for Mac OS X
# http://chameleonproject.org/
# https://github.com/BigZaphod/Chameleon/
framework 'Cocoa'
framework "UIKit" # garbage collected version, the current version of Chameleon ist not known to be GC-safe
###################
@mwmitchell
mwmitchell / fql.rb
Created March 26, 2011 21:38
A Minimalist Facebook FQL Client in Ruby
require "rubygems"
require "open-uri"
require "rack/utils"
require "json"
class Fql
class << self
attr_accessor :base_url
end
@maccman
maccman / gist:1232164
Created September 21, 2011 14:23 — forked from tvandervossen/gist:1231476
Mobile Safari viewport sizes on iOS 4.3 and 5
iPad
1024 × 690 In landscape on iOS 4.3
1024 × 672 In landscape on iOS 5
768 × 946 In portrait on iOS 4.3
768 × 928 In portrait on iOS 5
1024 × 660 Always showing bookmarks bar in landscape on iOS 4.3
1024 × 644 Always showing bookmarks bar in landscape on iOS 5
768 × 916 Always showing bookmarks bar in portrait on iOS 4.3
@moiristo
moiristo / gist:1245170
Created September 27, 2011 14:27
Rails3 way to redirect non-www domain to www domain
# Rails3 way to redirect non-www domain to www domain
# Single domain redirect
'example.com'.tap do |host|
constraints(:host => host) do
match '/(*path)', :to => redirect { |params, request| Addressable::URI.escape request.url.sub(host, "www.#{host}") }
end
end
@timgremore
timgremore / index.html.haml
Created January 3, 2012 21:13
Ember.js, document collection and polling...written in CoffeeScript
- title "#{@game.name}"
%h1= yield(:title)
#documents
= form_tag(assessment_game_documents_path(@game)) do
%ul
%script{ type: "text/x-handlebars" }
{{#collection Game.DocumentsCollectionView contentBinding="Game.documentsController"}}
%li {{content.name}}
{{/collection}}
@yusugomori
yusugomori / auth.coffee
Created April 10, 2012 04:03
User auth in SocketStream
#
# This gist contains both server side and client side scripts.
#
# Server:
# /server/rpc/auth.coffee
# /server/rpc/models/user.coffee
#
# Client:
# /client/code/modules/auth.coffee
# /client/code/app.coffee
@se4c0met
se4c0met / ls.php
Created November 23, 2012 09:33
Browse AppFog file system (PHP instance)
<?php
/*
due to the open_basedir restriction, $tgtPath must be something like the following path param:
http://<your domain>.aws.af.cm/ls.php?path=/var/vcap.local/dea/apps/f-0-21341234123412abcdefgc75cc0f96b9/app/
to discover what are the allowed paths, try supplying any path, e.g. '/' then view the error logs via:
af logs <your app name>
*/
@stakes
stakes / User.rb
Created January 22, 2012 22:56
Feature Flags / Rails + Mongoid
class User
include Mongoid::Document
# herein might appear a metric shitton of fields
# but what you need to know for feature flags follows
field :feature_flags, :type => Hash, :default => {}
# likewise, this is only what you need for