Skip to content

Instantly share code, notes, and snippets.

View gnepud's full-sized avatar

Peng Du gnepud

  • Grenoble, France
View GitHub Profile
@gnepud
gnepud / gist:1640335
Created January 19, 2012 14:35 — forked from jarod022/gist:1640319
Méthode choose_layout (annule le layout si Ajax)
# dans application_controller
private
# Charge le layout qui porte le même nom que le Namespace
# retourne aucun layout si la requête est en AJAX
def choose_layout
namespace = self.class.name.split("::").first.downcase
(request.xhr?) ? nil : namespace
end
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@gnepud
gnepud / gist:2047292
Created March 15, 2012 22:06 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@gnepud
gnepud / test_helper.rb
Created April 6, 2012 08:57 — forked from sethbro/test_helper.rb
MiniTest::Spec with Rails 3.2 setup
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'
require 'minitest/pride'
require 'capybara/rails'
class MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
@gnepud
gnepud / gist:2603827
Created May 5, 2012 16:30 — forked from ybart/gist:1070803
Google +1 Bookmarklet (Top Left)
javascript:(function(){div=document.createElement('div');e=document.createElement('g:plusone');div.style.position='fixed';div.style.top='8px';div.style.left='8px';div.style.zIndex=9999;div.appendChild(e);document.body.appendChild(div);e=window.document.createElement('script');e.setAttribute('src','https://apis.google.com/js/plusone.js');document.body.appendChild(e);})();
@gnepud
gnepud / Custom.css
Created May 8, 2012 08:10 — forked from star-szr/Custom.css
IR_Black Theme (with sidebar and view-source colors) for Chrome Developer Tools
/**********************************************/
/*
/* IR_Black Skin by Ben Truyman - 2011
/*
/* Based on Todd Werth's IR_Black:
/* http://blog.toddwerth.com/entries/2
/*
/* Inspired by Darcy Clarke's blog post:
/* http://darcyclarke.me/design/skin-your-chrome-inspector/
/*
@gnepud
gnepud / ember_handlebars.rb
Created June 8, 2012 08:09 — forked from dagda1/ember_handlebars.rb
ember_handlebars.rb
require 'tilt'
require 'json'
class EmberHandlebars < Tilt::Template
def self.default_mime_type
"application/javascript"
end
def prepare
end
@gnepud
gnepud / .pryrc
Created June 12, 2012 23:29 — forked from ches/.pryrc
Enable Hirb in Pry, and hack disable/enable to work in-session
if defined? Rails
begin
require 'hirb'
rescue LoadError
# Missing goodies, bummer
end
if defined? Hirb
# Dirty hack to support in-session Hirb.disable/enable
Hirb::View.instance_eval do
@gnepud
gnepud / rack_example.ru
Created June 17, 2012 18:07 — forked from mattetti/rack_example.ru
Very basic rack application showing how to use a router based on the uri and how to process requests based on the HTTP method used.
#########################################
# Very basic rack application showing how to use a router based on the uri
# and how to process requests based on the HTTP method used.
#
# Usage:
# $ rackup rack_example.ru
#
# $ curl -X POST -d 'title=retire&body=I should retire in a nice island' localhost:9292/ideas
# $ curl -X POST -d 'title=ask Satish for a gift&body=Find a way to get Satish to send me a gift' localhost:9292/ideas
# $ curl localhost:9292/ideas
@gnepud
gnepud / rack_example.ru
Created June 17, 2012 18:12 — forked from rkh/rack_example.ru
Very basic rack application showing how to use a router based on the uri and how to process requests based on the HTTP method used.
#########################################
# Very basic rack application showing how to use a router based on the uri
# and how to process requests based on the HTTP method used.
#
# Usage:
# $ rackup rack_example.ru
#
# $ curl -X POST -d 'title=retire&body=I should retire in a nice island' localhost:9292/ideas
# $ curl -X POST -d 'title=ask Satish for a gift&body=Find a way to get Satish to send me a gift' localhost:9292/ideas
# $ curl localhost:9292/ideas