Skip to content

Instantly share code, notes, and snippets.

View cmer's full-sized avatar

Carl Mercier cmer

  • Dallas-Fort Worth, TX
  • 05:18 (UTC -05:00)
View GitHub Profile
@cmer
cmer / _user.json.jbuilder
Created March 27, 2012 23:13
Poor man's caching for Jbuilder
# app/views/users/_user.json.jbuilder
json.(user, :id, :name, :age, :gender)
@cmer
cmer / powssl
Created March 22, 2012 02:52 — forked from paulnicholson/powssl
ssl with pow using stud

Instructions

  • Install stud $ brew install https://raw.github.com/paulnicholson/homebrew/master/Library/Formula/stud.rb
  • Download and install the powssl script $ curl https://raw.github.com/gist/2050941/3ea59efe8c7e9013c265313045a9fdda5c653963/powssl > ~/bin/powssl $ chmod +x ~/bin/powssl
  • Run powssl to create development certificate and configure stud.
  • $ powssl
@cmer
cmer / gist:2008671
Created March 9, 2012 20:59
Avoid console.log crash in IE when developer tools is closed
if(typeof(console) === 'undefined') {
var console = {};
console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}
@cmer
cmer / cjax.js.coffee
Created March 9, 2012 20:54
CJAX - History.js-PJAX hybrid that doesn't suck in IE
# This is a work in progress. I use it in production and it works very well, but use at your own risk!
@initCJAX = () ->
History = @History
$ = @jQuery
document = @document
return false unless @History.enabled
$ ->
contentSelector = ".main"
class @GroupActionMenuHandler
bind: ->
@handler_instance = this
$(document).on 'click', '.group-action-menu a', (e) =>
alert @handler_instance
class @GroupActionMenuHandler
bind: ->
$(document).on 'click', '.group-action-menu a', (e) =>
# The following line triggers error: GroupActionMenuHandler.selectMenuItem is not a function
this.selectMenuItem $(e.target).data('id')
false
selectMenuItem: (selectedItem) ->
alert 'hello'
@cmer
cmer / gist:1724957
Created February 2, 2012 18:20
Hetzner EX 4S UnixBench
# # # # # # # ##### ###### # # #### # #
# # ## # # # # # # # ## # # # # #
# # # # # # ## ##### ##### # # # # ######
# # # # # # ## # # # # # # # # #
# # # ## # # # # # # # ## # # # #
#### # # # # # ##### ###### # # #### # #
Version 5.1.3 Based on the Byte Magazine Unix Benchmark
Multi-CPU version Version 5 revisions by Ian Smith,
@cmer
cmer / gist:1566734
Created January 5, 2012 19:16
UnixBench comparison of EC2 and Joe's Data Center
apt-get install -y build-essential libx11-dev libgl1-mesa-dev libxext-dev perl perl-modules make
cd /tmp
wget http://byte-unixbench.googlecode.com/files/UnixBench5.1.3.tgz
tar xzvf UnixBench5.1.3.tgz
cd UnixBench
./Run
class Feed
fetch: ->
url = "http://example.org/feed?x=1"
url += "&ts=#{@oldest_item}" if @oldest_item
$.getJSON url, (data) ->
@oldest_item = data.oldest_item
# do something else with data
# How can I set a class variable from an anonymous function? For example, @oldest_item on line 4 is always null.
@cmer
cmer / hash.rb
Created December 19, 2011 03:16
Hash#value_at_path
class Hash
# Returns the value at the specified path.
# For example, [:foo, :bar, :baz] as a path would return the
# value at self[:foo][:bar][:baz]. If self doesn't contain one of
# the keys specified in path, nil is returned.
#
# This method is useful as it simplifies statements such as:
# value = h[:a][:b][:c][:d] if h[:a] && h[:a][:b] && h[:a][:b][:c]
# to
# value = h.value_at_path(:a, :b, :c, :d)