Skip to content

Instantly share code, notes, and snippets.

View cmer's full-sized avatar

Carl Mercier cmer

  • Dallas-Fort Worth, TX
  • 19:23 (UTC -05:00)
View GitHub Profile
@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)
##
## TAKEN FROM https://raw.github.com/benhoskings/delayed_job/c3a28f9714568c887271e492dd8c6710965278e8/lib/delayed/yaml_ext.rb
## Solves problems serializing strategies to yaml
##
# These extensions allow properly serializing and autoloading of
# Classes, Modules and Structs
require 'yaml'
class Module
@cmer
cmer / gist:1355664
Created November 10, 2011 18:25
net/http segfault
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
-- control frame ----------
c:0049 p:---- s:0258 b:0258 l:000257 d:000257 CFUNC :initialize
c:0048 p:---- s:0256 b:0256 l:000255 d:000255 CFUNC :open
c:0047 p:0029 s:0251 b:0251 l:0018d0 d:000250 BLOCK /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644
c:0046 p:0031 s:0249 b:0249 l:000248 d:000248 METHOD /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44
c:0045 p:0026 s:0237 b:0237 l:000236 d:000236 METHOD /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:87
c:0044 p:0038 s:0231 b:0231 l:0018d0 d:0018d0 METHOD /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644
@cmer
cmer / gist:1355634
Created November 10, 2011 18:18
Beanstalk-Client segfault
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:194: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
-- control frame ----------
c:0027 p:---- s:0111 b:0111 l:000110 d:000110 CFUNC :gets
c:0026 p:0015 s:0107 b:0107 l:000106 d:000106 METHOD /usr/local/rvm/gems/ruby-1.9.2-p180/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:194
c:0025 p:0011 s:0103 b:0103 l:000102 d:000102 METHOD /usr/local/rvm/gems/ruby-1.9.2-p180/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:200
c:0024 p:0013 s:0096 b:0096 l:000095 d:000095 METHOD /usr/local/rvm/gems/ruby-1.9.2-p180/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:215
c:0023 p:0169 s:0089 b:0087 l:000086 d:000086 METHOD /usr/local/rvm/gems/ruby-1.9.2-p180/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:100
c:0022 p:0026 s:0083 b:0083 l:000082 d:000082 METHOD /usr/local/rvm/gems/ruby-1.9.2-p180/gems/beanstalk-client-1.1.0/lib/beanst