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
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SoundCloud OAuth 2 User Agent Authentication Flow Demo</title>
<script type="text/javascript" charset="utf-8" src="javascript/jquery-1.4.2.js"></script>
<script type="text/javascript" charset="utf-8">
$(function () {
var extractToken = function(hash) {
#!/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 / juggernaut_heroku.md
Created June 2, 2011 01:26
Juggernaut on Heroku

Clone repo:

git clone git://github.com/maccman/juggernaut.git
cd juggernaut

Create Heroku app:

heroku create myapp --stack cedar
heroku addons:add redistogo:nano

git push heroku master

@mxriverlynn
mxriverlynn / 1-model.rb
Created June 17, 2011 01:37
serialize mongoid documents to json with an id attribute
class Foo
include Mongoid::Document
field :bar
end
foo = Foo.new(:bar => "baz")
foo.to_json # => { _id: "(some uuid)", bar: "baz" }
@shedd
shedd / assets.rake
Created June 20, 2011 18:05
Check asset encoding for valid UTF-8
namespace :assets do
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")
@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