Skip to content

Instantly share code, notes, and snippets.

@fblundun
fblundun / get-open-shards.sh
Last active January 14, 2016 09:53
Easy way to view open shards of a Kinesis stream
#!/bin/sh
aws kinesis describe-stream --stream-name $1 |
jq '.StreamDescription.Shards | map(select(.SequenceNumberRange.EndingSequenceNumber == null))'
implicit class RichDfType(df: DfType) {
def f(pairs: List[(String, AType)]): DfType = pairs match {
case head :: tail => df.withColumn(head._1, head._2).f(tail)
case Nil => df
}
}
@fblundun
fblundun / getRootDomain.js
Created January 7, 2016 12:07
How to get the root domain on which cookies can be written
function getRootDomain() {
var split = window.location.hostname.split('.');
var position = split.length - 1;
while (position >= 0) {
var currentDomain = split.slice(position, split.length).join('.');
document.cookie = 'unique=unique;domain=' + currentDomain + ';';
if (document.cookie.indexOf('unique') > -1) {
return currentDomain;
}
position -= 1;
@fblundun
fblundun / manual_geolocation.js
Created November 20, 2015 09:10
Manually sending geolocation events
if (!geolocationContextAdded && navigatorAlias.geolocation && navigatorAlias.geolocation.getCurrentPosition) {
navigator.geolocation.getCurrentPosition(function (position) {
var coords = position.coords;
var geolocationContext = {
schema: 'iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0',
data: {
latitude: coords.latitude,
longitude: coords.longitude,
latitudeLongitudeAccuracy: coords.accuracy,
altitude: coords.altitude,
@fblundun
fblundun / double_reverse_base64.py
Created October 30, 2015 09:31
List strings which may appear when a target string is doubly base 64-encoded
#!/usr/bin/python
import base64
import sys
input = sys.argv[1]
def get_combinations(s):
return [base64.urlsafe_b64encode('a'*i + s)[2*i:-4] for i in range(3)]
for x in [get_combinations(intermediate) for intermediate in get_combinations(sys.argv[1])]:
for y in x:
@fblundun
fblundun / enhancedecommerce.html
Last active October 21, 2015 12:14
Enhanced Ecommerce tag
<script>
// If this tag fires more than once (e.g. page view followed by ecommerce action),
// we don't want to repeat the trackPageView here
if (!window.snowplow) {
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.5.2/sp.js","snowplow"));
@fblundun
fblundun / fix_copyright.sh
Created September 29, 2015 11:19
Script to update Snowplow copyright notices
@fblundun
fblundun / AvroUtils.scala
Created September 16, 2015 14:51
Examples of using Avro to write to and read from files and in-memory streams
import org.apache.avro.io._
import org.apache.avro.specific._
import org.apache.avro.file.DataFileWriter
import java.util.ArrayList
import java.io.File
import example.avro._
import org.apache.avro.Schema
import org.apache.avro.generic._
import org.apache.avro.file.DataFileReader
import org.apache.avro.util.ByteBufferOutputStream
@fblundun
fblundun / incomplete.rb
Last active August 29, 2015 14:25
List Github issues not addressed in a branch
require 'octokit'
page = 1
issues = []
while true do
current_page = Octokit.list_issues('snowplow/snowplow', {milestone: 78, state: 'open',page: page}).map {|x| x.to_hash()};
if current_page.empty?
break
end
issues += current_page
@fblundun
fblundun / clones.js
Last active August 29, 2015 14:14
safari-tools
/**
* @license
* Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
* Build: `lodash exports="node" include="isArray, isFunction, isString, isObject, isDate, isUndefined, isNull, map, filter, find, compact, isEmpty, clone, cloneDeep" --debug --output src/js/lib_managed/lodash.js`
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <http://lodash.com/license>
*/
;(function() {