Skip to content

Instantly share code, notes, and snippets.

View filipeamoreira's full-sized avatar

Filipe A Moreira filipeamoreira

View GitHub Profile
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
@gavinheavyside
gavinheavyside / trivial_file_upload_service.rb
Created November 3, 2009 20:09
Trivial file upload service using Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
post '/:name/:filename' do
userdir = File.join("files", params[:name])
class Company
include Mongoid::Document
has_many :projects
end
class Project
include Mongoid::Document
has_many :project_zones
has_many :incidents
has_many_related :safety_inspectors
@defunkt
defunkt / installing-mustache-mode.el.md
Created March 6, 2010 10:11
Installing mustache-mode.el

https://github.com/mustache/emacs

In your shell:

cd ~/.emacs.d/vendor
curl -O https://github.com/mustache/emacs/raw/master/mustache-mode.el

In your Emacs config:

(add-to-list 'load-path "~/.emacs.d/vendor/mustache-mode.el")

@defunkt
defunkt / installing-mustache.vim.md
Created March 6, 2010 10:21
Installing mustache.vim

mustache.vim

In your shell:

cd ~/.vim
git clone git://github.com/juvenn/mustache.vim.git
mv mustache.vim/syntax/* syntax/
mv mustache.vim/indent/* indent/
mv mustache.vim/ftdetect/* ftdetect/

rm -rf mustache.vim

# 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
@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@makevoid
makevoid / Multipart file upload ruby.rb
Created April 7, 2010 02:08
Multipart file upload ruby
# from: http://kfahlgren.com/blog/2006/11/01/multipart-post-in-ruby-2/
# edited by makevoid, http://makevoid.com
URL = "http://localhost:3000/your_url"
TIMEOUT_SECONDS = 10
params = {}
file = File.open(filename, "rb")
params["file[replay]"] = file
@benbarnett
benbarnett / raphael-svg-buildjson
Created June 3, 2010 12:59
loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
// loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
buildJSON = function(paper) {
var svgdata = [];
svgdata.push({
width: 390,
height: 400
});
$.each(paper,
@ctrochalakis
ctrochalakis / ruby-debug + rvm + 1.9.2
Created July 2, 2010 09:01
ruby-debug + rvm + 1.9.2
#
gem install ruby-debug19 -- --with-ruby-include=/home/belbo/.rvm/src/ruby-1.9.2-head/