Skip to content

Instantly share code, notes, and snippets.

View JensRantil's full-sized avatar

Jens Rantil JensRantil

View GitHub Profile
@JensRantil
JensRantil / handle_tab_links.js
Created February 6, 2013 10:50
Code that makes it possible to link directly to a nested (Bootstrap) tab. Also, see http://stackoverflow.com/questions/7862233/twitter-bootstrap-tabs-go-to-specific-tab-on-page-reload
@JensRantil
JensRantil / example.html
Created February 8, 2013 10:26
Reusable jQuery/JavaScript snippet to have groups of HTML elements with the same height.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
equalizeHeights();
}
</script>
<style>
.box {
@JensRantil
JensRantil / execute.sh
Last active November 10, 2021 11:30
Simple test to test SIGINT signal handling of Go.
#!/bin/bash
# Executed on MacOSX
go build signal.go
./signal &
kill -INT $!
# Prints the "interrupt" and quits after 5 seconds, which is to be expected.
@JensRantil
JensRantil / example.html
Last active December 16, 2015 17:19
Improvement of http://stackoverflow.com/a/14774995/260805 that handles generated title attribute on timeago tags.
<html ng-app="MyApplication">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script src="timeago-angular.js" type="text/javascript"></script>
<script src="my-app.js" type="text/javascript"></script>
</head>
<body>
<div ng-controller="myController">
<span class="time-ago" title="{{ myTime }}"></span>
</div>
@JensRantil
JensRantil / .travis.yml
Created May 22, 2013 10:34
Example of multiple script/test commands.
language: python
python:
- "2.7"
- "3.2"
# command to run tests
script:
- python setup.py nosetests
- ./another_script.sh
Can't be tested locally due to same origin policies. I used Python's
SimpleHTTPServer for serving this:
$ python -m SimpleHTTPServer
@JensRantil
JensRantil / angular-post-fix.js
Created June 5, 2013 12:47
AngularJS module that can be reused in multiple Angular modules that are making POSTs to the backend.
// Modifies $httpProvider for correct server communication (POST variable format)
angular.module('http-post-fix', [], function($httpProvider) {
// This code is taken from http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/
// Use x-www-form-urlencoded Content-Type
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
// Override $http service's default transformRequest
$httpProvider.defaults.transformRequest = [function(data) {
/**
@JensRantil
JensRantil / custom_schematics_type.py
Created June 24, 2013 22:12
Custom schematics type.
class EventId(types.BaseType):
"""Schema type for aggregate event id."""
DIVIDER = ':'
def to_primitive(self, value):
if not isinstance(value, tuple):
raise ValidationError('{0} is not a tuple'.format(value))
if len(value) != 2:
raise ValidationError('{0} does not have two items'.format(value))
prim = EventId.DIVIDER.join(str(v) for v in value)
@JensRantil
JensRantil / CsvInnerJoiner.py
Last active December 19, 2015 16:19
Example: Chaining map reduce jobs in Disco. See https://groups.google.com/forum/#!topic/disco-dev/gSSxTqX_rj0
import sys
sys.path.append("/home/damian/disco/lib/")
from disco.core import Job, result_iterator
from disco.worker.classic.func import chain_reader
import csv, sys
class CsvInnerJoiner(Job):
partitions = 2
sort = True
@JensRantil
JensRantil / NonNullable.java
Last active December 21, 2015 10:48
NonNullable.java (see JavaDoc for more info).
import java.util.Map;
import java.util.Set;
/**
* An immutable object reference that may not be null.
* <p>
* This class has two purposes:
* <ul>
* <li>it adds a clearly documents the fact that a variable must not be
* <code>null</code>.</li>