Skip to content

Instantly share code, notes, and snippets.

View acorcutt's full-sized avatar
Making Stuff

Anthony Corcutt acorcutt

Making Stuff
View GitHub Profile
@acorcutt
acorcutt / RailsProxy.pac
Created January 5, 2011 17:59
This makes testing with domains and sub-domains easier on a mac, choose "Automatic Proxy Configuration" in Airport settings and set the URL to this file. Then any request to port 3000 will be pointed to the local rails server e.g. http://sub.mydomain.c
function FindProxyForURL(url, host) {
var port = url.match(/^\w{3,5}:\/\/[^:\/]*(:(\d+))?/)[2];
if(port){
if(port=="3000"){
var proxy = "PROXY localhost";
if(port){proxy += ":" + port;}
return proxy;
}
}
@acorcutt
acorcutt / providers_controller.rb
Created April 3, 2011 14:46
Rails twitter login
#a simple controller to login with twitter
#add gem 'oauth' to gemfile
#setup a route to /twitter => #show and /twitter/callback => #callback
class TwittersController < ApplicationController
def consumer
#return a consumer for twitter, add you key and secret here or dynamically grab from db etc.
OAuth::Consumer.new(
"key",
"secret",
:site => "https://api.twitter.com",
@acorcutt
acorcutt / application.rb
Created June 1, 2011 22:35
Turn off fixture creation
config.generators do |g|
g.fixture false
end
#instead of
current_user && current_user.admin?
#do
current_user.try(:admin?)
@acorcutt
acorcutt / gist:1043559
Created June 23, 2011 20:31
Turn Safari Plugins (Flash) On|Off Command
defaults read com.apple.Safari WebKitPluginsEnabled
defaults write com.apple.Safari WebKitPluginsEnabled -boolean true | false
defaults write com.apple.Safari WebKitPluginsEnabled 0 | 1
@acorcutt
acorcutt / jquery.myplugin.js
Created June 28, 2011 16:42
JQuery Plugin Starter
// JQuery Plugin Starter
// ----------------------------------------------------
// Setup a namespace we can use for data, events etc.
// Wraps methods internally with support for arguments.
//
// $('div').myplugin(); //call init
// $('div').myplugin({color:'green'}).fadeIn(); //init with options and chained
// $('div').myplugin('destroy'); //custom method
// $('div').myplugin('custom',10,2); //custom method with arguments
//
SecureRandom.uuid
@acorcutt
acorcutt / gist:1099813
Created July 22, 2011 16:41
Post array of text_field's in rails as array
<%-# items is an array on object e.g. object.items = [1,2,3], we want to display as list of fields, and post back as an array - note the backwards ][ which makes is do this! -%>
<% @object.items.each do |i| %>
<%=f.text_field "items][",:value=>i,:id=>"item-#{SecureRandom.uuid}" %>
<% end %>
@acorcutt
acorcutt / Indexer.rb
Created November 26, 2011 19:49
Indextank Indexer
module Indexer
# Add indexed fields to model
# TODO - make this work in embedded e.g. self.index_embedded(*names)
module Indexes
extend ActiveSupport::Concern
included do
class_attribute :_index_fields
class_attribute :_index_texts
@acorcutt
acorcutt / import.js.erb
Created May 8, 2012 14:11
Import URL into assets pipeline
// Instead of copying js plugins to assets/ import them from a url.
// Obviously works best with pre-compiled assets
<%=open('https://raw.github.com/documentcloud/backbone/master/backbone.js
').read%>