Skip to content

Instantly share code, notes, and snippets.

View dbryand's full-sized avatar

Dave Bryand dbryand

View GitHub Profile
@dbryand
dbryand / gist:325615
Created March 8, 2010 20:19
Browsercms monkey patch to allow "uncountable" named content blocks
require 'cms/path_helper'
module Cms
module PathHelper
def cms_index_path_for(resource, options={})
options[:only_path] = false
cms_index_url_for(resource, options)
end
def cms_index_url_for(resource, options={})
@dbryand
dbryand / gist:6602855
Last active December 23, 2015 07:48
Will's rotx
# Build a hash of keys to use for lookup.
def build_key(x, encrypt=true)
chars = ('a'..'z').to_a
{}.tap do |key|
chars.each_with_index do |char, idx|
if(encrypt)
key[char] = chars[(idx + x) % 26] # rotate x clicks forward
else
key[char] = chars[(idx - x) % 26] # rotate x clicks backwards
@dbryand
dbryand / gist:17cff141c431c47c0948
Created February 5, 2015 09:44
Postgres: Find by email in array of JSON objects
// Inspiration: http://stackoverflow.com/a/19868697/1221591
select
*
from
events,
json_array_elements(events.raw->'attendees') as attendees
where
attendees->>'email' = '[email protected]';
@dbryand
dbryand / gist:5cbda9f81d5b9655c685
Created February 9, 2015 03:54
Recursive CTEs to do non-blocking updates in Postgres
// https://news.ycombinator.com/item?id=9018756
One of my favorite idioms lately for doing bulk updates without incurring lock contention is to chain CTEs, like so:
with candidate_rows as (
select id
from table
where conditions
limit 1000
for update nowait
), update_rows as (
update table
@dbryand
dbryand / safari-pip-video-bookmarklet.js
Last active January 13, 2017 02:49
Bookmarklet for Safari to Picture-in-Picture the currently playing video
// Create a bookmark in safari with this as the address
javascript: (function() {var video; document.querySelectorAll('video').forEach(function(vid) { if (!vid.paused) video = vid; }); if (video) { video.webkitSetPresentationMode('picture-in-picture') } })()