Skip to content

Instantly share code, notes, and snippets.

View hvrauhal's full-sized avatar

Heikki Rauhala hvrauhal

View GitHub Profile
@hvrauhal
hvrauhal / express-static-server.js
Created August 19, 2015 10:19
Serve static files using express.js
var express = require('express')
var app = express()
var port = process.env.PORT || 8010
module.exports = app
app.use(require('morgan')('combined'))
app.use(function (req, res, next) {
console.log('starting', req.url, JSON.stringify(req.headers))
next()
})
@hvrauhal
hvrauhal / README.md
Last active May 23, 2022 05:51
Aggressively caching squid for http://registry.npmjs.org/

Caching http://registry.npmjs.org/ aggressively with squid

We run a lot of project in our automated test environment and they spend a lot of time doing npm install. One way to speed up npm install and hammer the registry a little less is to use the http-version of the registry and to pass the requests through a proxy.

However, the npm requests include an authorization-header and the responses come with an ETag and Cache-Control: max-age=60, so with default squid settings there is a lot of roundtrips to registry.npmjs.org that result in 304's.

This is what the requests look like once npm has cached the first set of responses:

GET http://registry.npmjs.org/sntp HTTP/1.1

@hvrauhal
hvrauhal / init.el
Created May 10, 2015 15:29
.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(package-initialize)
(defvar my-packages '(rainbow-delimiters
clojure-mode
@hvrauhal
hvrauhal / jasenmaksut_2015.applescript
Created April 26, 2015 19:25
HWC Henkilökohtaiset jäsenmaksusähköpostit Mail.appia käyttäen
on run argv
set recipientAddress to item 1 of argv
set refNumber to item 2 of argv
set theSubject to "HWC Jäsen- ja lautapaikkamaksut 2015"
set theContent to "Hei,
Helsinki Windsurfing Clubin maksut kaudelta 2015 ovat:
* Jäsenmaksu 20€
* Lautapaikkavuokra 30€
@hvrauhal
hvrauhal / install_texlive.sh
Last active August 29, 2015 14:19
Install TexLive on openshift as a portable install with network install
#!/bin/bash
set -e
TMP_INSTALL_DIR=$(mktemp --directory --tmpdir texlive-install-XXXXXXXX)
trap "rm -rf $TMP_INSTALL_DIR" EXIT
pushd $TMP_INSTALL_DIR
# Following line from http://stackoverflow.com/a/2916159/61175
perl -p -i -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' < ${OPENSHIFT_REPO_DIR}/texlive.profile.template > $TMP_INSTALL_DIR/texlive.profile
curl http://www.nic.funet.fi/pub/TeX/CTAN/systems/texlive/tlnet/install-tl-unx.tar.gz | tar xzf -
pushd install-tl*
./install-tl -profile $TMP_INSTALL_DIR/texlive.profile || cat <<EOF
@hvrauhal
hvrauhal / promise-garbage-collection.js
Last active August 29, 2015 14:08
It would be nice if this did not consume all memory
var BPromise = require('bluebird')
var i = 0, n = 100000000;
function mapManyThings() {
return BPromise.map(new Array(1000), function () {
return BPromise.delay(1).then(function () {
i++
var aThousandFloats = new Array(1000).map(function () {
return Math.random()
})
@hvrauhal
hvrauhal / oikotie-reittiopas-to-location.user.js
Last active November 3, 2018 09:03
A greasemonkey script for adding routes from reittiopas to the result cards of http://asunnot.oikotie.fi. Only on Firefox.
// ==UserScript==
// @name oikotie-reittiopas-to-location
// @namespace my-oikotie-api.herokuapp.com
// @description Shows the reittiopas route to the on sale apartments
// @include http://asunnot.oikotie.fi/myytavat-asunnot*
// @version 1.1
// @grant GM_getValue
// @grant GM_setValue
// @license The MIT License (MIT); http://opensource.org/licenses/MIT
// ==/UserScript==
_bold=$(tput bold)
_underline=$(tput smul)
_normal=$(tput sgr0)
__prompt_command() {
local vcs base_dir sub_dir ref last_command
sub_dir() {
local sub_dir
sub_dir=$(stat -f "${PWD}")
sub_dir=${sub_dir#$1}