Skip to content

Instantly share code, notes, and snippets.

Avatar

Jacob Burenstam buren

View GitHub Profile
View .github-open.bash
# USAGE
# 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 "https://github.com/$user_repo"
@buren
buren / snippets.cson
Created Sep 11, 2018
Atom snippet - Ruby method missing template
View snippets.cson
'.source.ruby':
'def method_missing .. end':
'prefix': 'defmm'
'body':
'''
def method_missing(method_name, *arguments, &block)
if ${1}.respond_to?(method_name)
${1}.public_send(method_name, *arguments, &block)
else
super
@buren
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
# USAGE:
# $ check_redirects --help
# or
# $ ruby check_redirects.rb --help
require 'bundler/inline'
gemfile do
@buren
buren / snippets.cson
Created Aug 2, 2018
Atom snippet - Ruby gem configuration template
View snippets.cson
'.source.ruby':
'Insert gem configuration block':
'prefix': 'gconfig'
'body':
'''
def self.configuration
@configuration ||= Configuration.new
end
def self.config
@buren
buren / snippets.cson
Created Aug 1, 2018
Atom snippet - Ruby optparse template
View snippets.cson
'.source.ruby':
'Insert Ruby optparser':
'prefix': 'optparse'
'body':
'''
require 'optparse'
options = {}
@buren
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
sitemap_urls.map do |url|
sitemap_xml = open(url).read
sitemap = WaybackArchiver::Sitemap.new(sitemap_xml)
sitemap.urls
end.flat_map { |url| puts url }
@buren
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 = CrawlEvent.new do |on|
# on.every_found_url { {|url| puts "Found URL: #{url}" }
# on.every_page_title { {|title| puts "Page title: #{title}" }
@buren
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.