Skip to content

Instantly share code, notes, and snippets.

View nu7hatch's full-sized avatar

Krzysztof Kowalik nu7hatch

  • Warsaw, Poland
View GitHub Profile
@nu7hatch
nu7hatch / Gemfile
Created August 4, 2010 09:32
Padrino authentication with Warden
# ...
gem 'padrino-warden', :git => "git://github.com/zmack/padrino-warden.git"
gem 'authtools'
@nu7hatch
nu7hatch / gist:508715
Created August 4, 2010 20:15
Resque with ActionMailer
class Notifier < ActionMailer::Base
def self.perform(method, *args)
#self.send(method, *args).deliver
self.send("deliver_#{method}", *args)
end
def some_notification(user)
# ...
end
@nu7hatch
nu7hatch / script.js
Created August 11, 2010 13:30
Clear form values with jQuery
$(':input', '#form_id')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
@nu7hatch
nu7hatch / telegraph_example_app.rb
Created August 11, 2010 20:27
Example server writen with Telegraph framework
require 'rubygems'
require 'telegraph'
before do
say "foo"
end
after(:foo) do
say "bar"
end
@nu7hatch
nu7hatch / git-setup-home
Created August 26, 2010 14:17
Git repos management helpers
#!/bin/bash
# usage: git-setup-home PATH
#
# It creates 'git' user and group, and prepares given home directory.
# By default git home dir is '/var/git'.
if [ $1 ] ; then
export GIT_HOME=$1
else
@nu7hatch
nu7hatch / _flash_messages.html.haml
Created September 2, 2010 10:08
Flash messages and form errors in good way
- if flash.keys.size > 0
.flash-messages
- flash.each do |type, message|
%div(class="flash-message flash-#{type}")= message
@nu7hatch
nu7hatch / example.html
Created September 7, 2010 14:20
Simple banner rotator with jQuery
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<link href="rotate.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="rotate.js"></script>
<script type="text/javascript">
$(window).load(function() {
startRotator("#rotator");
})
</script>
class Myapp
controller :libaries do
# ...
end
controller :book, :parent => :library do
before do
@lib = Library.find(params[:library_id] rescue nil
end
MyApp.controllers :product do
parent :shop, :optional => true
parent :category, :optional => true
get :show, :with => :id do
# generated url: "/(shop/#{params[:shop_id]}/)(category/#{params[:category_id]}/)product/show/#{params[:id]}"
# url_for(:product, :show, :id => 10) => "/product/show/10"
# url_for(:product, :show, :shop_id => 5, :id => 10) => "/shop/5/product/show/10"
# url_for(:product, :show, :shop_id => 5, :category_id => 1, :id => 10) => "/shop/5/category/1/product/show/10"
end
require "rubygems"
require "mounter"
module FooApp
extend Mounter
controllers do
get "/foo" do
"Foo..."
end