Skip to content

Instantly share code, notes, and snippets.

@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()
@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
@ktheory
ktheory / dd.log
Last active November 10, 2023 23:41
EC2 EBS-SSD vs instance-store performance on an EBS-optimized m3.2xlarge
# /tmp/test = EBS-SSD
# /mnt/test = instance-store
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 3.26957 s, 82.1 MB/s
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
// 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)
#!/bin/bash
set -eu
shopt -s nullglob
if [[ -n ${RUN:-} ]]; then
dry=
else
dry=echo
fi
@branneman
branneman / better-nodejs-require-paths.md
Last active January 30, 2024 04:32
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@FiloSottile
FiloSottile / browser_request
Created December 12, 2013 23:20
Analysis of the new GMail image proxy
{
"accept-language": "en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4",
"accept-encoding": "gzip,deflate,sdch",
"cache-control": "max-age=0",
"connection": "keep-alive",
"accept": "image/webp,*/*;q=0.8",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36",
"host": "filosottile.info",
"if-modified-since": "Wed, 31 Oct 2012 23:52:07 GMT"
}
@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 ;
@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;
@ms-tg
ms-tg / jdk8_optional_monad_laws.java
Created November 11, 2013 21:14
Does JDK8's Optional class satisfy the Monad laws? Yes, it does.
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```