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)
@endolith
endolith / Has weird right-to-left characters.txt
Last active October 22, 2023 12:58
Unicode kaomoji smileys emoticons emoji
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@kdwinter
kdwinter / authenticable.rb
Created June 14, 2010 21:52
Authlogic with Mongoid (in spirit of http://pastie.org/503478)
module Authenticable
def self.included(model)
model.class_eval do
extend ClassMethods
include InstanceMethods
field :username
field :email
field :crypted_password
field :password_salt
@kdwinter
kdwinter / authenticable.rb
Last active September 5, 2015 05:45
Authlogic plugin for MongoMapper
module Authenticable
extend ActiveSupport::Concern
included do
key :username, String
key :email, String
key :crypted_password, String
key :password_salt, String
key :persistence_token, String
key :login_count, Integer, :default => 0
require 'ostruct'
class OpenStruct
DEPTH = 5
def self.deep(data, depth=0, &blck)
return data if depth > DEPTH
return data unless data.class == Hash
hash = {}
data.each do |key, value|
key = blck.call(key) if block_given?
@jmazzi
jmazzi / peepcode.rb
Created May 24, 2011 13:54
A script to download all Peepcode screencasts with ruby & wget (supports resume)
require 'mechanize'
@username = 'user@domain.com'
@password = 'hi2u'
@download_path = File.expand_path 'downloads'
@wget_cookie = File.expand_path(File.dirname(__FILE__)) + '/wget-cookies.txt'
unless File.directory? @download_path
puts "@{download_path} doesn't exist!"
exit
@chriseppstein
chriseppstein / readme.md
Created August 31, 2011 21:57 — forked from mislav/Gemfile
How to integrate Compass with Rails 3.1 asset pipeline

This gist is no longer valid. Please see Compass-Rails for instructions on how to install.

@jcasimir
jcasimir / render_and_redirect.markdown
Created September 11, 2011 21:29
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@moomerman
moomerman / two_factor_ssh.rb
Created September 23, 2011 11:32
Two Factor SSH Authentication
#!/usr/bin/env ruby
require 'rubygems'
require 'rotp'
require 'time'
user = ARGV[0]
secret = ARGV[1]
abort unless user and secret
trap("INT") do
require 'sinatra'
require 'eventmachine'
get '/' do
stream(:keep_open) do |out|
count = 0
timer = EM.add_periodic_timer(1) do
out << "<p>ohai</p>\n"
count += 1
if count == 10