Skip to content

Instantly share code, notes, and snippets.

View DouweM's full-sized avatar

Douwe Maan DouweM

View GitHub Profile
@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;
@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

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: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)
@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"]>]
# 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",
datetime = DateTime.parse('2013-07-14T09:00')
tz = datetime.in_time_zone # => Sun, 14 Jul 2013 09:00:00 UTC +00:00
tz.instance_variable_set(:@time_zone, ::Time.find_zone!("CET"))
tz.instance_variable_set(:@period, tz.send(:get_period_and_ensure_valid_local_time))
tz # => Sun, 14 Jul 2013 09:00:00 CEST +02:00
# :-)
@DouweM
DouweM / request
Last active December 20, 2015 20:09 — forked from abhishek0/request
curl http://localhost:3000/users -d '{"user": { "first_name": "Abhishek", "login_info_attributes": { "password": "p"}}}'
@DouweM
DouweM / somefile.rb
Last active December 21, 2015 05:39
class TutorsController < ApplicationController
before_action :authenticate_user!
respond_to :html
def new
@tutor = current_user.build_tutor
respond_with @tutor
end
@DouweM
DouweM / VerEx.rb
Last active March 8, 2016 00:44 — forked from svineet/VerEx.rb
# This is a program trying to implement Verbal Expressions
# See this for more info - http://verbalexpressions.github.io/
def VerEx
VerExClass.new
end
class VerExClass
attr_accessor :regex