Skip to content

Instantly share code, notes, and snippets.

View JensRantil's full-sized avatar

Jens Rantil JensRantil

View GitHub Profile
This is the first file.
@JensRantil
JensRantil / events.json
Last active December 22, 2015 04:28
Three example events for CouchDB.
[{
"_id": "FD12E675-52BF-499C-B651-25D6B92BA8BE:1",
"globalId": "7C768D9E-DA0E-4413-98D0-5C730BAEB461",
"aggregateType": "contact",
"event": {
"type": "createContact",
"firstname": "Jens",
"lastname": "Rantil",
"telephone": "+46401234567",
},
@JensRantil
JensRantil / example-view.json
Last active February 8, 2021 21:31
Example event view projection for CouchDB event store.
{
"_id": "_design/eventProjections",
"views": {
"map": "function(doc) {
if (doc.aggregateType=='contact' &&
(doc.event.type=='ContactCreated' ||
doc.event.type=='DescriptionChanged') &&
doc.event.description) {
var colon = doc._id.indexOf(':');
var version = parseInt(doc._id.substr(colon + 1));
@JensRantil
JensRantil / Image.java
Created September 12, 2013 13:32
My new favourite Java class implementation.
public class Image {
public void getImage() {
return;
}
}
@JensRantil
JensRantil / go-compile.sh
Created September 17, 2013 10:12
$ brew install go --cross-compile-all Debug information.
$ brew install go --cross-compile-all
==> Downloading https://go.googlecode.com/files/go1.1.2.src.tar.gz
Already downloaded: /Library/Caches/Homebrew/go-1.1.2.tar.gz
==> ./make.bash --no-clean
==> ./make.bash --no-clean
==> ./make.bash --no-clean
/private/tmp/go-q5rl/go/src/cmd/5l/../ld/lib.c:661:9: error: no case matching constant switch condition '53' [-Werror]
switch(thechar){
^~~~~~~
1 error generated.
@JensRantil
JensRantil / output.sh
Created September 17, 2013 10:18
Debug information for `brew install go --cross-compile-common`
$ brew install go --cross-compile-common
==> Downloading https://go.googlecode.com/files/go1.1.2.src.tar.gz
Already downloaded: /Library/Caches/Homebrew/go-1.1.2.tar.gz
==> ./make.bash --no-clean
==> ./make.bash --no-clean
==> ./make.bash --no-clean
/private/tmp/go-5MJo/go/src/cmd/5l/../ld/lib.c:661:9: error: no case matching constant switch condition '53' [-Werror]
switch(thechar){
^~~~~~~
1 error generated.
@JensRantil
JensRantil / discojob.py
Created October 1, 2013 07:36
Generate a parametrized Disco job. See http://disco.readthedocs.org/en/latest/start/tutorial_2.html for example of class based map reduce jobs.
def generate_job(param):
"""Generate a job the yields only rows identical to `param`."""
class CsvInnerJoiner(Job):
def map(self, rows, params):
for row in rows:
if row == param:
yield row, "found"
@JensRantil
JensRantil / double-sort.py
Created October 3, 2013 13:06
Today's favourite code reviewal.
from django.utils.datastructures import SortedDict
dictionary = {}
# populating `dictionary`...
sortedDictionary = SortedDict()
for word in sorted(dictionary.iterkeys()):
sortedDictionary[word] = dictionary[word]
@JensRantil
JensRantil / fabfile.py
Created October 11, 2013 21:24
Example of creating a "supertask" in Fabric. The tasks spawns a couple of smaller tasks.
from fabric.api import *
from __future__ import print_function
@task
def supertask():
execute(create_user)
execute(deploy)
@task
@JensRantil
JensRantil / FirstName.java
Created February 8, 2014 09:25
As close as one can get to a Java typedef. That is, wrapping a type. Lots of boilerplate code for something that could be so short and concise.
/**
* A first name.
* <p>
* In other programming languages, you would be able to write something like
* <code>
* typedef FirstName String;
* </code>
*/
public class FirstName {
private String firstName;