I hereby claim:
- I am alassek on github.
- I am alassek (https://keybase.io/alassek) on keybase.
- I have a public key ASCER3RZ4eL9jqSNbXVviFayarCOAT2JXki5SwZ6hhHopwo
To claim this, I am signing this object:
require "global_id" | |
module Sidekiq | |
module GlobalIDMiddleware | |
class Processor | |
def call(_worker_class, job, *) | |
job["args"].map!(&method(:process)) | |
yield | |
end |
def Redis.Mutex(name, expires:, redis: Redis.current, &block) | |
raise ArgumentError, "block required" unless block_given? | |
if block.arity.zero? | |
success = block | |
block = proc do |on| | |
on.success(&success) | |
on.failure(&proc{}) | |
end | |
end |
type Maybedoer struct { | |
err error | |
} | |
func (m Maybedoer) Maybe(f func() error) { | |
if m.err == nil { | |
c.err = f() | |
} | |
} |
namespace :db do | |
desc "Do a clean reset of your DB from a backup file" | |
task refresh: [:environment, :check_protected_environments] do | |
filename = ARGV.last | |
jobs = ENV.fetch('JOBS', 2) | |
database = ActiveRecord::Base.connection.current_database | |
abort "Usage: rails db:refresh filename" if filename == 'db:refresh' | |
abort "Can't find: #{filename}" unless File.exists? filename | |
abort "Can't find pg_restore, make sure it is in your $PATH" unless system "which", "pg_restore" |
I hereby claim:
To claim this, I am signing this object:
I've been doing some work lately with JSON documents in PostgreSQL using jsonb
columns. You can query these documents
using a GIN index in PG, but the syntax can be a little cumbersome
SELECT "events".* FROM "events" WHERE "events"."body" @> '{"shift":{"user_id":2}}'
You have to construct the right side of the query as a JSON string, which is a bit annoying. So I wondered if I could adapt Arel to do the tedious stuff for me.
class ApplicationController < ActionController::Base | |
before_filter :require_authentication | |
private | |
def require_authentication | |
unless current_certificate.verify(public_key) | |
head :forbidden | |
end | |
end |
/** | |
* `window.location` is a BAD api. Doesn't have a prototype, 'too much recursion' error | |
* if you try to inspect the constructor. Monkey-patching causes random disappearances | |
* of the monkey-patched function in Chrome, cloning causes 'too much recursion' in FF. | |
* | |
* This is what I'm reduced to. ಠ_ಠ | |
**/ | |
(function () { | |
function Location () { |
# By Henrik Nyh <http://henrik.nyh.se> 2008-01-30. | |
# Free to modify and redistribute with credit. | |
require "rubygems" | |
require "hpricot" | |
module TextHelper | |
# Like the Rails _truncate_ helper but doesn't break HTML tags or entities. | |
def truncate_html(text, max_length = 30, ellipsis = "...") |
(function () { | |
function extendEach () { | |
var args = Array.prototype.slice.call(arguments), | |
child = this; | |
_.each(args, function (proto) { | |
child = child.extend(proto); | |
}); |