Skip to content

Instantly share code, notes, and snippets.

# 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)
# 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
desc "Parse picasa photo feed."
task :parse do
require 'dm-core'
require 'open-uri'
require 'nokogiri'
config = File.open(Pathname(Sinatra::Application.root)/"config/picasa.yml") { |file| YAML.load(file) }
picasa = Picasa.new
picasa.login(config['credentials']['email'], config['credentials']['password'])
@jcbozonier
jcbozonier / gist:647644
Created October 26, 2010 19:55
All the SQL I need to write using Sinatra + DataMapper so far... :)
class User
include DataMapper::Resource
property :id, Serial
property :email, String
property :password, Text
property :income, Decimal
has n, :monthly_bills
end
@pierot
pierot / makro_nokogiri.rb
Created January 23, 2011 14:00
Makro Resto + Fuel scraping
require 'sinatra'
require 'builder'
require 'nokogiri'
require 'uri'
require 'open-uri'
$: << File.join(File.dirname(__FILE__), '..', 'app')
configure do
set :root, File.join(File.dirname(__FILE__), '..')
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'haml'
DataMapper.setup(:default, 'sqlite3::memory:')
class Message
include DataMapper::Resource
@daz4126
daz4126 / main.rb
Created August 10, 2011 16:38
Short, Long and Pretty Urls - Using Sinatra & DataMapper to demonstrate different types of urls
require 'sinatra'
require 'data_mapper'
require 'slim'
require 'digest/sha1'
DataMapper.setup(:default, ENV['DATABASE_URL'] || File.join("sqlite3://",settings.root, "development.db"))
class Note
include DataMapper::Resource
property :id, Serial
@sethvincent
sethvincent / Gemfile
Created March 15, 2012 00:29
sinatra, omniauth, and datamapper
source :rubygems
gem 'foreman'
gem 'oa-oauth'
gem 'dm-core'
gem 'dm-sqlite-adapter'
gem 'dm-migrations'
gem 'rack', "~> 1.3.6"
gem 'sinatra'
gem 'thin'
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active July 17, 2024 15:03
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@wdullaer
wdullaer / install.sh
Last active July 11, 2024 08:59
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"