Skip to content

Instantly share code, notes, and snippets.

@sr
sr / app.rb
Created December 29, 2008 13:45
require "rubygems"
require "rack"
$:.unshift File.dirname(__FILE__) + "/lib"
require "sinatra/base"
class Sinatra::Application
get "/" do
"Hello World"
end
end
@sr
sr / serve.rb
Created December 28, 2008 02:09
# WTFPL
# Requires http://github.com/rtomayko/sinatra/tree/hoboken
require "rubygems"
require "rack"
require "thin"
require "pathname"
require "addressable/uri"
require "sinatra/base"
#!/bin/bash
cat <<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Notes en Vrac</title>
<link rel="alternate" type="application/atom+xml"
title="Notes en Vrac (Atom)" href="/notes/feed" />
<style type="text/css">
@import "/2008/10-crumb.css";
@sr
sr / from.rb
Created December 14, 2008 01:06 — forked from bmizerany/from.rb
get '/:id' do
@vent = Vent.get(params[:id])
erb :show
end
# show post
get '/:id.xml' do
@vent = Vent.get(params[:id])
builder :show
end
#!/usr/bin/env ruby
base = File.dirname(__FILE__) + "/../code/git-wiki"
require base + '/git-wiki'
set :public, base + '/public'
set :port, 4567
set :env, :production
disable :run, :reload
@sr
sr / gist:25914
Created November 17, 2008 21:31
#!/usr/bin/env ruby
def truncate(text, length = 30, truncate_string = "...")
if text.nil? then return end
l = length - truncate_string.length
(text.length > length ? text[0..l] + truncate_string : text).to_s
end
def date
Time.now.strftime('%Y/%m/%d %H:%M')
end
=begin
Shooter
<http://gist.github.com/25886>
Harry Vangberg <http://trueaffection.net>
Simon Rozet <http://purl.org/net/sr/>
EXAMPLE
IRC.shoot('irc://irc.freenode.net:6667/integrity', :as => "IntegrityBot") do |channel|
@sr
sr / sinatra-apps.txt
Created November 4, 2008 17:39
let's make a list of sinatra-based apps
The list is now managed directly in Sinatra's website.
<http://www.sinatrarb.com/wild.html>
require 'rubygems'
require 'open-uri'
require File.dirname(__FILE__) + '/gchartrb/lib/gchartrb'
def get_chart(color, data)
chart = GoogleChart::PieChart.new
chart.width = 600
chart.height = 300
total = data.inject(0) { |sum, (label, value)| sum = sum + value }
require 'rubygems'
require 'grit'
%w(saloon config couchy dst dumbapp git-wiki integrity).each do |repository|
repo = Grit::Repo.new(File.expand_path("~/code/#{repository}"))
commits = repo.log.collect { |commit| commit.message }
total_commits = commits.length.to_f
cosmetic_commits = commits.select { |message| message =~ /cosmetic/ }.length.to_f