Skip to content

Instantly share code, notes, and snippets.

# This is a cheap stab at demonstrating the behavior of
# Inotify::CREATE. That is, CREATE will trigger inotify events
# immediately upon file creation.
require 'inotify'
require 'fileutils'
# Method which fakes a slow write by sleeping for one second.
def slow_write(filename)
File.open(filename, "w") do |f|
diff -ur marcbowes-UsingYAML-590c028/lib/using_yaml/array.rb UsingYAML-590c028/lib/using_yaml/array.rb
--- marcbowes-UsingYAML-590c028/lib/using_yaml/array.rb 2010-03-06 22:14:19.000000000 +0200
+++ UsingYAML-590c028/lib/using_yaml/array.rb 2010-03-29 18:05:01.000000000 +0200
@@ -25,5 +25,6 @@
# Load in the extensions for this instance
array.extend(extensions)
+ array
end
end
$ cat Gemfile
source 'http://rubygems.org'
gem "rails", ">=3.0.5"
# To use debugger
# gem 'ruby-debug'
gem "guid"
gem "mysql2"
@marcbowes
marcbowes / gist:1899731
Created February 24, 2012 09:31
Envelope encryption in Ruby using OpenSSL
# Explanation at http://stackoverflow.com/questions/5212213/ruby-equivalent-of-php-openssl-seal/9428217#9428217
# Implementation
class EnvelopeEncryption
require "openssl"
# This method takes in plaintext and produces ciphertext and an
module NameIdCache
def self.included(base)
m = Module.new
base.all.each do |record|
m.__send__(:define_method, record.name) do
record.record_id # using #record_id because OpenStruct is iffy about #id
end
end
base.extend(m)
end
module NameIdCache
def self.included(base)
m = Module.new
base.all.each do |record|
cache_key = NameIdCache.cache_key(base, record)
Rails.cache.write(cache_key, record.id)
m.__send__(:define_method, record.name) do
Rails.cache.fetch(cache_key) do
@marcbowes
marcbowes / gist:2224748
Created March 28, 2012 08:30
Why I didn't spend $480.11 at ThinkGeek (Livechat transcript)
Marc: Hi. I get this error on checkout: Transaction was declined by processor.
Sade: Hi Marc!
Sade: I will look into this
Sade: What is the order number?
Marc: I'm at checkout
Marc: 35246f7e5
Marc: Earlier I tried via PayPal but that order was rejected too :-(
Sade: Hmm, I am seeing that it being rejected by us.
Sade: Is there anyway you can place the order when you get back to the states?
Marc: I don't live in the states
@marcbowes
marcbowes / gist:4017369
Created November 5, 2012 14:12
Dedup posters
require "digest/md5"
require "set"
found = Set.new
def md5sum(filename)
content = File.read(filename)
Digest::MD5.hexdigest(content)
end
@marcbowes
marcbowes / gist:4976522
Last active December 13, 2015 21:18
Failing at ember-rails
git clone https://github.com/marcbowes/ember-hacking.git
bundle
rails s
open http://localhost:3000/
Nothing appears in the console and I get the following error in the console
DEBUG: ------------------------------- ember.js?body=1 (line 339)
DEBUG: Ember.VERSION : 1.0.0-rc.1 ember.js?body=1 (line 339)
@marcbowes
marcbowes / gist:5117577
Created March 8, 2013 16:13
Ember not booting cleanly
DEBUG: -------------------------------
DEBUG: Ember.VERSION : 1.0.0-rc.1
DEBUG: Handlebars.VERSION : 1.0.0-rc.3
DEBUG: jQuery.VERSION : 1.9.1
DEBUG: -------------------------------
TypeError: Application.registerInjection is not a function [Break On This Error]
injection: function(app, stateManager, property) {