Skip to content

Instantly share code, notes, and snippets.

@drogus
drogus / Gemfile
Created April 23, 2012 18:34
Webmachine + ActionView pt2
source "http://rubygems.org"
gem "webmachine"
gem "actionpack"
gem "thin"
gem "datamapper"
gem "dm-migrations"
gem "dm-sqlite-adapter"
gem "debugger"
@drogus
drogus / Gemfile
Created April 2, 2012 23:18
Webmachine + ActionView
source "http://rubygems.org"
gem "webmachine"
gem "actionpack"
gem "thin"
gem "datamapper"
gem "dm-migrations"
gem "dm-sqlite-adapter"
gem "debugger"
@drogus
drogus / config.ru
Created March 4, 2012 22:13
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
#!/bin/bash
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
gem install linecache19-0.5.13.gem
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include="${MY_RUBY_HOME/rubies/src}"
gem install ruby-debug19
rm ruby-debug-base19-0.11.26.gem
rm linecache19-0.5.13.gem
CREATE OR REPLACE FUNCTION array_array_agg_sfunc(state integer[][], p integer[]) RETURNS integer[][] AS $$
BEGIN
IF p IS NULL THEN
RETURN state;
END IF;
IF array_dims(state) IS NULL THEN
RETURN ARRAY[p];
END IF;
RETURN array_cat(state, p);
END;
@drogus
drogus / persistent_connections.rb
Created October 17, 2011 18:32
persistent connections example
# This example fetches accounts of my 10 followers using Github's API
# One version uses Connection: keep-alive, the other one uses Connection: close
require 'net/https'
require 'uri'
require 'json'
require 'benchmark'
def request(uri, persistent = true)
req = Net::HTTP::Get.new uri
@drogus
drogus / Kirkfile
Created October 17, 2011 18:27
request streaming
log :level => :all
rack "config.ru" do
listen 3030
# Set the file that controls the redeploys. This is relative to
# the applications root (the directory that the rackup file lives
# in). Touch this file to redepoy the application.
watch "config.ru"
end
@drogus
drogus / gist:978579
Created May 18, 2011 13:40
SproutCore FormView
{{#view SC.FormView target="Todos.userSessionController" action="signIn"}}
<!-- name="name" will be used to bind text fied to proper target,
insertNewLine will automatically call action -->
{{view Todos.TextField placeholder="Email" name="email"}}
{{view Todos.TextField placeholder="Password" type="password" name="password"}}
{{#view SC.Submit text="Sign in"}}
{{/view}}
Todos.projectsCollectionView = SC.TemplateCollectionView.extend({
itemView: SC.TemplateView.extend({
isSelected: function() {
var selected = this.get('selected'),
content = this.get('content');
return selected && content && selected.get("storeKey") === content.get("storeKey");
}.property("selected").cacheable(),
mouseUp: function() {
test("fetching records", function() {
stop(5000);
var records = store.find(Todo);
records.addObserver('status', function() {
var titles = records.map(function(item) { return item.get('title'); }).sort();
equals(titles[0], "Bar");
equals(titles[1], "Foo");
start();
});