Skip to content

Instantly share code, notes, and snippets.

View muescha's full-sized avatar

Muescha muescha

View GitHub Profile
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
# [] - Eqauls to
# ^ - Not equals to
# =~ - LIKE
# >, >=, <, <= works as expected
#
# Examples :
#
# Item.where(:colour['Red'], :quanity > 10, :price <= 200)
# Post.where(:comments_count >= 1, :taggings_count < 5)
# User.where(:country ^ 'US') # Non american users
@dimus
dimus / Hash.from_xml using Nokogiri
Created March 17, 2010 14:29
Adding Hash.from_xml method using Nokogiri
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
@huy
huy / Hash.from_xml
Created February 10, 2011 05:29
Convert xml to hash using Nokogiri
# USAGE: Hash.from_xml(YOUR_XML_STRING)require 'rubygems'
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#123129
7
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
@140bytes
140bytes / LICENSE.txt
Created May 9, 2011 16:13
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@carlhoerberg
carlhoerberg / gist:976228
Created May 17, 2011 09:59
How to list DataMapper enum options
class Entity
include DataMapper::Resource
property :enum_property, Enum[:a, :b, :c]
end
Entity.enum_property.options[:flags] #=> [:a, :b, :c]
# or
Entity.enum_property.flag_option.values #=> [:a, :b, :c]
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@jrochkind
jrochkind / gist:2161449
Created March 22, 2012 18:40
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@stevebourne
stevebourne / Gemfile
Created April 15, 2012 19:28
Add facebook auth to a Clearance app, using omniauth-facebook
gem 'omniauth'
gem 'omniauth-facebook'
gem 'clearance'
@MicahElliott
MicahElliott / rbenv-howto.md
Created April 17, 2012 18:11
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev