Skip to content

Instantly share code, notes, and snippets.

View amrnt's full-sized avatar

Amr Tamimi amrnt

View GitHub Profile
@postmodern
postmodern / referer_control.rb
Created October 12, 2009 00:53
A Rack middleware app to control access to paths based on the Referer header.
module Rack
#
# RefererControl is a Rack middleware app which restricts access to paths
# based on the Referer header. Using RefererControl you can make sure
# users follow the intended flow of a website. If a controlled path is
# visited with an unacceptable Referer URI, then a simple 307 Redirect
# response is returned.
#
# RefererControl should also make Cross Site Request Forgery (CSRF) a
# little more difficult to exploit; but not impossible using JavaScript.
get "/about" => 'info#about', :as => 'about'
get "/privacy" => 'info#privacy', :as => 'privacy'
get "/license" => 'info#license', :as => 'license'
get "/mission" => 'info#mission', :as => 'mission'
get "/contact" => 'info#contact', :as => 'contact'
@ilpoldo
ilpoldo / paperclip.rb
Created February 27, 2010 13:22 — forked from stympy/paperclip.rb
mongomapper paperclip
module Paperclip
module ClassMethods
def has_attached_file name, options = {}
include InstanceMethods
write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
attachment_definitions[name] = {:validations => []}.merge(options)
after_save :save_attached_files
before_destroy :destroy_attached_files
class Account
include Mongoid::Document
include Mongoid::Timestamps
field :subdomain, :type => String
embeds_many :users
accepts_nested_attributes_for :users
validates_presence_of :name, :subdomain
validates_uniqueness_of :subdomain, :case_sensitive => false
@karmi
karmi / workers.rake
Created July 22, 2010 15:58
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@mbbx6spp
mbbx6spp / .gitconfig
Created July 25, 2010 14:43
Susan Potter's .gitconfig file from November 2007 blog post. Updated since November 2007 with new aliases or options.
# Migrating my old .gitconfig blog post from 2007 to here so I can update it easier.
# Original URL:
# http://geek.susanpotter.net/2007/11/my-gitconfig.html
[user]
name = Susan Potter # make sure you change this
email = me@susanpotter.net # make sure you change this
[color]
diff = auto
status = auto
branch = auto
module Devise
module Orm
module MongoMapper
module Hook
def devise_modules_hook!
extend Schema
include Compatibility
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }
trait RestHelper extends LiftRules.DispatchPF {
...
/**
* A function that chooses JSON or XML based on the request..
* Use with serveType
*/
implicit def jxSel(req: Req): Box[JsonXmlSelect] =
if (jsonResponse_?(req)) Full(JsonSelect)
else if (xmlResponse_?(req)) Full(XmlSelect)
else None
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active May 16, 2024 16:51
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@fcalderan
fcalderan / inception-javascript.js
Created November 2, 2010 09:42
inception explained as a 4 nested javascript closures
/*
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
*
* Activate javascript console =)
*/
<script>
console.group("inception movie");