Skip to content

Instantly share code, notes, and snippets.

View grampelberg's full-sized avatar

Thomas Rampelberg grampelberg

View GitHub Profile
@grampelberg
grampelberg / deploy.bash
Last active August 29, 2015 13:56
auto-deploy
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: deploy.bash
This will bootstrap a git checkout of the repo and then try to deploy it.
USAGE
}; function --help { -h ;} # A nice way to handle -h and --help
def getAverageSentiment(responses: Seq[Response], label: String): Double = responses.map { response =>
(response.json \\ label).head.as[Double]
}.sum / responses.length.max(1) // avoid division by zero
<script src="/src/hospitality.js"></script>
<script>
hospitality.init({
visit: {
new: function() { alert('new-user'); },
return: function() { alert('return-user'); }
}
});
</script>
var tester = mocha.run();
tester.on("fail", function(test, err) {
setTimeout(function() { throw err}, 1);
});
import urllib
import urllib2
print urllib2.urlopen("http://localhost:8080/login",
urllib.urlencode({ "username": "foo", "password": "bar" }).read()
#!/usr/bin/env bash
# Take all the positional parameters ($*) and normalize them
# -ab1 becomes -a -b 1 or -b1 -a becomes -b 1 -a
# Note that the : after b means that it should have a value instead of
# just being the boolean flag that a is.
args=`getopt ab: $*`
# Rewrite ARGV with the output of getopt
set -- $args
#!/usr/bin/env bash
usage() {
cat << EOF
usage: $0 [options] <argv>...
Options:
-h Show help options.
-v Print version info.
EOF
/*global module:false*/
"use strict";
var _ = require('underscore');
module.exports = function(grunt) {
_.each([
'grunt-contrib-watch',
@grampelberg
grampelberg / gist:4735238
Created February 7, 2013 23:35
nginx CORS config
location / {
# For CORS
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers 'Authorization,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-CSRF-Token,X-Zendesk-Lotus-Version';
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type "text/plain charset=UTF-8";
return 204;
@grampelberg
grampelberg / gist:4601476
Created January 23, 2013 02:59
No more proxy for me zendesk!
(function() {
var scope = {};
with(scope) {
return {
events: {
'app.activated':'doSomething',
'click header': 'check'