Skip to content

Instantly share code, notes, and snippets.

@mjtko
mjtko / main.js
Created March 29, 2012 15:42
closure exports under sprockets
/*
*= include fragments/prefix
*= include lib/util
*= include fragments/util_suffix
*/
@mjtko
mjtko / ability.rb
Created March 21, 2012 15:40
Cancan ability definition for being able to edit any Project from an Array
can :edit_any, Array do |arr|
arr.any?{|p| p.is_a?(Project) && can?(:edit, p)}
end
module MyModule
def foo
puts 'new foo'
end
end
class MyClass
def foo
puts 'old foo'
end
@mjtko
mjtko / location.rb
Created February 12, 2012 19:06 — forked from drale2k/gist:1810253
class Location < ActiveRecord::Base
DEFAULT_OPTS = {:units => :km}
class << self
def near(coords, radius = 10, opts = {})
options = DEFAULT_OPTS.merge(options)
radius = radius.to_i
# do stuff with coords and radius and options
end
end
@mjtko
mjtko / bmi.js
Created January 26, 2012 08:57
Javascript added by O2 transparent proxy (de-obfuscated)
var bmi_htmlEdit = 0;
var bmi_ie;
var bmi_ns;
var bmi_safari;
var bmi_imageObjSelected;
var bmi_ffx_op_toolTip = "Shift+R improves the quality of this image. Shift+A improves the quality of all images on this page.";
var bmi_toolTip = "Shift+R improves the quality of this image. CTRL+F5 reloads the whole page.";
var bmi_ns_tooltip = "Shift+Reload reloads the whole page.";
var bmi_toolTipSeperator = " ... ";
var bmi_concatStr = "bmi_orig_img";
<ul class="photos">
<% @album.photos.in_groups_of(20, false) do |photos| %>
<div class="slide">
<% photos.each do |photo| %>
<li class="photo">
<%= link_to image_tag(photo.source(:square)), photo.source(:large), rel: 'gallery', class: 'fancybox-thumb' %>
</li>
<% end %>
</div>
<% end %>
@mjtko
mjtko / outputs.txt
Created December 21, 2011 12:40
YAML memory leaks
◯ markt@hibbert$ rvm use 1.9.2 [ruby-1.9.3-p0] 10174 [12:36:27]
Using /Users/markt/.rvm/gems/ruby-1.9.2-p290
◯ markt@hibbert$ ruby /tmp/test_yaml.rb syck [ruby-1.9.2-p290] 10183 [12:38:05]
RUBY_VERSION: 1.9.2 290 syck
5000 ... markt 74572 20.8 0.1 2450584 11516 s011 S+ 12:38pm 0:00.12 ruby /tmp/test_yaml.rb syck
10000 ... markt 74572 20.8 0.2 2459800 16064 s011 S+ 12:38pm 0:00.17 ruby /tmp/test_yaml.rb syck
15000 ... markt 74572 47.3 0.2 2459800 16072 s011 S+ 12:38pm 0:00.23 ruby /tmp/test_yaml.rb syck
20000 ... markt 74572 47.3 0.2 2459800 16072 s011 S+ 12:38pm 0:00.29 ruby /tmp/test_yaml.rb syck
25000 ... markt 74572 62.8 0.2 2459800 16076 s011 S+ 12:38pm 0:00.34 ruby /tmp/test_yaml.rb syck
@mjtko
mjtko / gist:1354648
Created November 10, 2011 11:26 — forked from stuffness/gist:1354646
Different database adapters... per platform ;)
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'mysql2', :platforms => :ruby # causes this gem to be skipped on windows
@mjtko
mjtko / sass-rails-importer-monkey-patch.rb
Created November 6, 2011 20:13
Initializer to monkey patch in https://github.com/rails/sass-rails/pull/70 before it's accepted upstream
require 'sass/rails/importer'
if defined?(Sass::Rails::VERSION) && Sass::Rails::VERSION[0..3] >= '3.1.'
Rails.logger.warn ' == MONKEY == Patching sass-rails: https://github.com/rails/sass-rails/pull/70'
Rails.logger.warn " == MONKEY == Please remove #{__FILE__} once Sass::Rails upstream has pulled in the fix"
# monkey patch to incorporate https://github.com/rails/sass-rails/pull/70
module Sass
module Rails
class Importer
def resolve(name, base_pathname = nil)
@mjtko
mjtko / flash_preserver.rb
Created October 12, 2011 15:48
middleware that preserves flashes over multiple redirects
# use via this in application.rb:
# config.middleware.insert_after(ActionDispatch::Flash, FlashPreserver)
class FlashPreserver
def initialize(app)
@app = app
end
def call(env)
flash = (session = env['rack.session']) && session['flash']