Skip to content

Instantly share code, notes, and snippets.

Jacob Burenstam buren

Block or report user

Report or block buren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .github-open.bash
# In any local GitHub repository run
# $ github_open
github_open() {
local remotename="${@:-origin}"
local remote="$(git remote -v | awk '/^'"$remotename"'.*\(push\)$/ {print $2}')"
[[ "$remote" ]] || return
local user_repo="$(echo "$remote" | perl -pe 's/.*://;s/\.git$//')"
open "$user_repo"
buren / snippets.cson
Created Sep 11, 2018
Atom snippet - Ruby method missing template
View snippets.cson
'def method_missing .. end':
'prefix': 'defmm'
def method_missing(method_name, *arguments, &block)
if ${1}.respond_to?(method_name)
${1}.public_send(method_name, *arguments, &block)
buren / check_redirect.rb
Created Aug 16, 2018
Given a CSV file with expected redirects - verify that each redirect is performed correctly.
View check_redirect.rb
#!/usr/bin/env ruby
# $ check_redirects --help
# or
# $ ruby check_redirects.rb --help
require 'bundler/inline'
gemfile do
buren / snippets.cson
Created Aug 2, 2018
Atom snippet - Ruby gem configuration template
View snippets.cson
'Insert gem configuration block':
'prefix': 'gconfig'
def self.configuration
@configuration ||=
def self.config
buren / snippets.cson
Created Aug 1, 2018
Atom snippet - Ruby optparse template
View snippets.cson
'Insert Ruby optparser':
'prefix': 'optparse'
require 'optparse'
options = {}
buren / subdomain_matcher.rb
Created Jun 23, 2018
Match valid subdomain string.
View subdomain_matcher.rb
SUBDOMAIN_MATCHER = /\A([a-z][a-z\d]*(-[a-z\d]+)*|xn--[\-a-z\d]+)\z/i
['as a', nil],
['a-a', 0],
['todd2', 0],
['todd-2', 0],
['todd-admin', 0],
['_todd-admin', nil],
['-todd-admin', nil],
View print_sitemap_urls.rb
require 'open-uri'
require 'wayback_archiver' # requires `gem install wayback_archiver`
sitemap_urls = ARGV do |url|
sitemap_xml = open(url).read
sitemap =
end.flat_map { |url| puts url }
buren / event_emitter.rb
Last active Jan 23, 2018
Simple event emitter
View event_emitter.rb
# Returns an event emitter class with given event names
# @return [Object] the event emitter class
# @param [String, Symbol] event_names
# @example Simple event emitter
# class CrawlEvent < EventEmitter(:found_url, :page_title)
# end
# event = do |on|
# on.every_found_url { {|url| puts "Found URL: #{url}" }
# on.every_page_title { {|title| puts "Page title: #{title}" }
buren / cross-origin-local-storage.js
Created Nov 1, 2017
Cross origin local storage sharing example (using an iframe and postMessage)
View cross-origin-local-storage.js
const CrossOriginLocalStorage = function(currentWindow, iframe, allowedOrigins, onMessage) {
this.allowedOrigins = allowedOrigins;
let childWindow;
// some browser (don't remember which one) throw exception when you try to access
// contentWindow for the first time, it works when you do that second time
try {
childWindow = iframe.contentWindow;
} catch(e) {
childWindow = iframe.contentWindow;
View articles.js
const articles = {
data: [{
id: 3,
type: 'articles'
attributes: {
title: 'LMA-kort',
slug: 'lma-kort',
body_html: '<p>LMA-kort är ett bevis på...</p>',
language_id: 192,
traits: ['bank_account', 'skill_ids', 'resume', 'personal_letter'], // zero to many
You can’t perform that action at this time.