Skip to content

Instantly share code, notes, and snippets.

// Index:
r.table("heroes").indexCreate("idEquipment", function(doc) {
return doc("equipment").map(function(equipment) {
return [doc("id"), equipment]
})
}, {multi: true}).run(conn, callback)
// Query
r.table("heroes").getAll([1, "boots"], {index: "idEquipment"}).run(conn, callback)
@keesun
keesun / EnableHello.java
Created January 18, 2012 15:18
Spring 3.1's @import & ImportBeanDefinitionRegistrar
@Retention(value = RetentionPolicy.RUNTIME)
@Import(HeloIBDR.class)
public @interface EnableHello {
String name();
}
@neojp
neojp / Node.js: Using "supervisor" with "Locomotive"
Created February 16, 2012 19:59
Runs a Locomotive app, listens and auto-reloads server if code changes are found.
# node-supervisor: https://github.com/isaacs/node-supervisor
# locomotive: http://locomotivejs.org/
supervisor --watch app/controllers,config,config/environments,config/initializers -- node_modules/locomotive/bin/lcm.js server
@mariocesar
mariocesar / models.py
Last active December 12, 2015 00:29
Conveniently register model methods as constraints, that will check before saving the model
from functools import wraps
from django.db import models
from django.core.exceptions import ValidationError
class ConstraintModel(models.Model):
class Meta:
abstract = True
def _fill_constraints_register(self):
@bouk
bouk / immutable.js
Last active March 15, 2016 00:00 — forked from cpojer/immutable.js
// Copyright 2004-present Facebook. All Rights Reserved.
/**
* Immutable data encourages pure functions (data-in, data-out) and lends itself
* to much simpler application development and enabling techniques from
* functional programming such as lazy evaluation.
*
* While designed to bring these powerful functional concepts to JavaScript, it
* presents an Object-Oriented API familiar to JavaScript engineers and closely
* mirroring that of Array, Map, and Set. It is easy and efficient to convert to
@metasim
metasim / ScalaInterpreterExample.java
Last active November 6, 2017 10:02
Demo code for defining a scala class dynamically (as string) and load it into Java.
package eri;
import scala.collection.Iterator;
import scala.collection.JavaConversions;
import scala.collection.Seq;
import scala.reflect.internal.util.BatchSourceFile;
import scala.reflect.io.AbstractFile;
import scala.runtime.AbstractFunction1;
import scala.runtime.BoxedUnit;
import scala.tools.nsc.GenericRunnerSettings;
#!/bin/bash
set -eu
shopt -s nullglob
if [[ -n ${RUN:-} ]]; then
dry=
else
dry=echo
fi
@TooTallNate
TooTallNate / mp3player.js
Created October 24, 2012 17:42
node.js command line MP3 player in 9 lines of code!
var fs = require('fs');
var lame = require('lame');
var Speaker = require('speaker');
fs.createReadStream(process.argv[2])
.pipe(new lame.Decoder())
.on('format', function (format) {
this.pipe(new Speaker(format));
});
@timyates
timyates / Currying.java
Last active March 7, 2020 07:11
Currying and composition in Java 8
package java8tests ;
import java.util.function.BiFunction ;
import java.util.function.Function ;
public class Currying {
public void currying() {
// Create a function that adds 2 integers
BiFunction<Integer,Integer,Integer> adder = ( a, b ) -> a + b ;
@willscott
willscott / analytics.conf
Created November 12, 2016 18:49
Google Analytics Proxy
location = /analytics.js {
proxy_hide_header Alt-Svc;
resolver 8.8.8.8 ipv6=off;
proxy_pass https://www.google-analytics.com/analytics.js;
break;
}
location = /analytics {
access_by_lua_block {
ngx.req.read_body()
local body = ngx.req.get_body_data()