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
@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;
@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}" }
View key_struct.rb
class KeyStruct < Struct
def initialize(**keyword_args)
keyword_args.each do |key, value|
if members.include?(key)
self[key] = value
else
raise ArgumentError, "Unknown key struct member: #{key}"
end
end
end
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.