Skip to content

Instantly share code, notes, and snippets.

View bensie's full-sized avatar

James Miller bensie

View GitHub Profile
@alloy
alloy / zomg.rb
Created February 14, 2014 10:44
Some controls have internal subviews you’d want to modify, but you cannot control the class that’s used internally. This example shows extending just that singleton (the view instance) by defining the method inline. This is preferable to using ‘categories’, because those affect _all_ instances of that class.
def presentAlert
alert = UIAlertView.new
# ...
textField = alert.textFieldAtIndex(0)
# *Only for this UITextField instance*, move the leftView 4 points to the right.
def textField.leftViewRectForBounds(bounds)
CGRectOffset(super, 4, 0)
end
@brianpattison
brianpattison / application_serializer.js
Created May 2, 2014 04:22
Spree + Ember-Data is coming...
Backend.ApplicationSerializer = DS.RESTSerializer.extend({
extractMeta: function(store, type, payload) {
store.metaForType(type, {
count: payload.count,
currentPage: payload.current_page,
pages: payload.pages
});
delete payload.count;
delete payload.current_page;
@seven1m
seven1m / fix_find_all.rb
Last active August 29, 2015 14:04
Fix old Rails 1.x finder syntax.
#!/usr/bin/env ruby
# A script to convert old Rails 1.x finder syntax, e.g. find(:all, ...) and find(:first, ...)
# to use where() and friends.
# gem install parser unparser
# cd path/to/rails_app
# ruby fix_find_by.rb
require 'parser/current'
// Examples:
//
// button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "form_to_link"
// button_to "New Alert", new_alert
//
jQuery(document).ready(function($) {
jQuery('.form_to_link').each(function(el){
var form = el.parents('form');
form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>');
form.hide();
@mislav
mislav / update-ree-passenger.sh
Created May 26, 2009 17:08
Update Ruby Enterprise Edition and Passenger
set -e
# for a setup script see http://gist.github.com/32917
PASSENGER=2.2.3
REE="ruby-enterprise-1.8.6-20090610"
PREFIX=/opt/$REE
# git checkout of git://github.com/FooBarWidget/passenger.git
cd ~/passenger
git fetch origin
@pat
pat / application_controller.rb
Created June 15, 2009 21:51
Returning HTML in AJAX calls, without layouts.
# Three things to add:
# * before_filter call
# * action_has_layout? method (if you have one, combine them)
# * adjust_for_inline
#
class ApplicationController < ActionController::Base
# ...
before_filter :adjust_for_inline
@schacon
schacon / gist:171255
Created August 20, 2009 18:39
my .gitconfig file
[user]
name = Scott Chacon
email = schacon@gmail.com
[alias]
serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git
unstage = reset HEAD
lol = log --pretty=oneline --abbrev-commit --graph --decorate
branches = !git-branches
st = status
[gui]
~vp(master)> cat ~/.gitconfig
...SNIP...
[alias]
datetag = !git tag `date \"+%Y%m%d%H%M\"`
update = pull --rebase
commdiff = log --pretty=oneline --left-right
...SNIP...
~vp(master)> git commdiff master...staging
>bb569b9a8c70a61ecffd4def3ac5e460848e0f36 Merge branch 'master' into staging
>f95b7db13fb48b3b5e1c2c484d00909a89f468d5 bulk edit on search page is no longer experimental
class JsonHax
def initialize(app)
@app = app
end
def call(env)
if env['CONTENT_TYPE'] == 'application/json'
env['CONTENT_TYPE'] = 'application/xml'
env['REQUEST_URI'].gsub!(/\.json/, '.xml')
alias reload='. ~/.bashrc'
alias ea="$EDITOR ~/bin/dotfiles/bash/aliases && reload"
alias ee="$EDITOR ~/bin/dotfiles/bash/env && reload"
alias eh="$EDITOR ~/bin/dotfiles/bash/heroku && reload"
# Processes
alias tu='top -o cpu'
alias tm='top -o vsize'
# Projects