Skip to content

Instantly share code, notes, and snippets.

View DouweM's full-sized avatar

Douwe Maan DouweM

View GitHub Profile
# config/initializers/char_converter.rb
require 'uri'
module Support
class CharConverter
SANITIZE_ENV_KEYS = [
"HTTP_COOKIE", # bad cookie encodings kill rack: https://github.com/rack/rack/issues/225
"HTTP_REFERER",
"PATH_INFO",
@DouweM
DouweM / output
Created November 8, 2012 12:35
#{rel}_ids= with Mongoid HABTM
% ./test.rb
a.b_ids = [b.id]
a.b_ids: ["509ba6a40b32cb7486000001"]
a.bs: []
b.a_ids: []
b.as: []
a.bs = [b]
a.b_ids: ["509ba6a40b32cb7486000001"]
a.bs: [#<B _id: 509ba6a40b32cb7486000001, _type: nil, a_ids: ["509ba6a40b32cb7486000002"]>]
@DouweM
DouweM / gist:3966970
Created October 28, 2012 00:09
Proposed Mongoid::Relations::Proxy#eager_load_ids rewrite
def eager_load_ids(metadata, ids)
klass, foreign_key = metadata.klass, metadata.foreign_key
eager_loaded = klass.any_in(foreign_key => ids).entries
ids.each do |id|
IdentityMap.clear_many(klass, { foreign_key => id })
end
eager_loaded.each do |doc|
base_id = doc.__send__(foreign_key)

I want to display these 4 player wrapper divs as in a grid. I.e.

---------- ----------
|player 1| |player 2|
---------- ----------
---------- ----------
|player 3| |player 4|

@DouweM
DouweM / gist:1848219
Created February 16, 2012 22:07
Mac AutoTyper
display dialog "Enter text to auto type:" buttons {"Cancel", "OK"} default button 2 default answer ""
set theResult to the result
if the button returned of theResult is "Cancel" then
return
end if
set theText to the text returned of theResult as text
if theText is "" then
@DouweM
DouweM / gist:1811188
Created February 12, 2012 22:25
Overall Gauge
<iframe id="overall_gauge_frame" src="about:blank" style="display: none;"></iframe>
<script type="text/javascript">
var _gauges = _gauges || [];
(function() {
frame = document.getElementById('overall_gauge_frame')
doc = frame.contentDocument || frame.contentWindow.document
var t = document.createElement('script');
t.type = 'text/javascript';
t.async = true;