Skip to content

Instantly share code, notes, and snippets.

@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

@sapient
sapient / xirr.rb
Created November 14, 2011 20:07
XIRR Function Written for Ruby 1.9.2
require 'date'
require 'bigdecimal/newton'
require 'bigdecimal/math'
include Newton
class XIRR
def initialize(datevalues)
@datevalues = datevalues
@zero = BigDecimal::new("0.0")
@jch
jch / net_http_default_proxy.rb
Created December 14, 2011 19:56
make all net/http requests go through an http proxy
require 'net/http'
module Net
module DefaultProxy
# Defaults all requests through Net::HTTP through an http proxy.
# Example:
# require 'net/http'
# require 'net/http_extensions'
# Net::HTTP.set_http_proxy!
#
@arndttouby
arndttouby / pivotal_tracker.rake
Last active September 29, 2015 11:37
git hooks for pivotal tracker automation
require "rubygems"
require "pivotal-tracker"
namespace :pt do
desc "shows a list of available pivotal tracker tickets to create a git feature branch for"
task :list_tickets do
token = `git config --get pivotal.token`
projectid = `git config --get pivotal.projectid`
if token.blank? || projectid.blank?
puts "###################### ACHTUNG! #######################"
@mathias
mathias / buttons.coffee
Created January 30, 2012 15:31
Haml + Coffeescript Tweet button and Like button
((d, s, id) ->
js = undefined
fjs = d.getElementsByTagName(s)[0]
return if d.getElementById(id)
js = d.createElement(s)
js.id = id
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"
fjs.parentNode.insertBefore js, fjs
) document, "script", "facebook-jssdk"
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@zachwill
zachwill / gist:2001993
Created March 8, 2012 16:42
Reload Google Chrome from Vim
" Reload Google Chrome on Mac from Vim.
" Adapted from: https://github.com/gcollazo/BrowserRefresh-Sublime/
function! ChromeReload()
python << EOF
from subprocess import call
browser = """
tell application "Google Chrome" to tell the active tab of its first window
reload
end tell
tell application "Google Chrome" to activate
@jondkinney
jondkinney / README.md
Last active December 14, 2023 06:39
jondkinney's console vim setup

Console VIM and Tmux setup compatible with Mac OS X and Linux.

Installation

Install by running the following command in your terminal:

exec 3<&1;bash <&3 <(curl https://gist.githubusercontent.com/jondkinney/2040114/raw/vim.sh 2> /dev/null)
@mybeky
mybeky / vim.rb
Created April 12, 2012 02:52
Vim formula for Homebrew with python, ruby and clipboard enabled
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
url 'https://vim.googlecode.com/hg/', :revision => '2d107086903a'
version '7.3.584'
def install
system "./configure",
"--with-features=huge",
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"