Skip to content

Instantly share code, notes, and snippets.

View subelsky's full-sized avatar
🧘‍♂️

Mike Subelsky subelsky

🧘‍♂️
View GitHub Profile
require('core')
App.IframeView = SC.View.extend({
emptyElement: '<iframe></iframe>',
content: '',
noIframeText: '',
frameBorder: 0,
render: function() {
var content = this.get('content')
begin
text = JSON.generate(refresh_hash)
render :text => Iconv.iconv('utf-8','latin1',text).to_s
rescue StandardError
logger.warn("JSON generation error in refresh controller: #{$!}")
render :text => "Problem reading messages, please try again", :status => 500
end
export GIT_EDITOR="mate -w"
export LESS="-erX" # makes git diff look nicer
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ '
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'OI', :timeout => 60 }
$stderr.puts "Using memcached on localhost:11211"
rescue StandardError
config.cache_store = nil
$stderr.puts "memcached not running, caching to memory"
end
# modified from http://www.mikeperham.com/2009/03/03/using-memcache-client-16x-in-rails-23
# Brain surgery to use our own version of memcache-client without having to modify activesupport directly.
# Unload any previous instance of the class
if Object.const_defined? :MemCache
Object.instance_eval { remove_const :MemCache }
end
# Ensure that the memcache-client gem path is at the front of the loadpath
$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/gems/memcache-client-1.7.4/lib')
class Tracker
def track_event(a,b,c)
@queue ||= Queue.new
start_pushing_thread
hash = { :a => a, :b =>, :c => c }
@queue << hash
end
private
@subelsky
subelsky / macvim command key mapping
Created January 18, 2011 01:10
maps the apple key plus a number to change tabs in Macvim, just like any other app
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
@subelsky
subelsky / gist:878603
Created March 20, 2011 19:39
Possible memory leak in therubyracer
require "rubygems"
require "v8"
require "ostruct"
require "memprof"
funcs = []
3.times do
cxt = V8::Context.new
funcs << cxt.eval("f = function(arg) { return arg.a + arg.b }")
@subelsky
subelsky / null_zero_obj.rb
Created July 1, 2011 20:51
using a null zero object
# I have a function that looks up a monthly report which may or may not exist yet (e.g. if
# you look at the start of a month, before I've gotten around to generating that month's
# report)
#
# where the report isn't generated I just want to return "0" for each column in this report;
# so what I do is return an instance of the below object whenever there's no report
# available (thus avoiding any "try" unpleasantness) - something about this slightly
# bothers me though. Is there a more elegant/simpler way I should consider?
class NullZeroObject
@subelsky
subelsky / Gemfile
Created July 28, 2011 14:17
Getting SSL, Capybara, Rails 3, and Devise to work together
gem "rack-ssl", "1.3.2"
# when Capybara issue 409 or 422 get resolved, you can switch back to the official
# capybara gem
# https://github.com/jnicklas/capybara/pull/409
# https://github.com/jnicklas/capybara/pull/422
gem "capybara", git: "https://github.com/mcolyer/capybara.git", branch: "fix-ssl-redirects"