Skip to content

Instantly share code, notes, and snippets.

View dln's full-sized avatar
🚀

Daniel Lundin dln

🚀
View GitHub Profile
import boto.ec2
instances = boto.ec2.connect_to_region('eu-west-1').get_all_instances()
by_address = dict((r.instances[0].ip_address, r.instances[0].id) for r in instances)
@dln
dln / curl_json.sh
Created May 15, 2013 08:04
Simple util function for juggling json with curl
function curl_json() {
out=/tmp/curl_json.json
echo > $out $out.err $out.pretty
curl -s -H "Content-Type: application/json" -H "Accept: application/json" $@ > $out
jq -s -C . < $out > $out.pretty 2>$out.err
test -s $out.err && cat $out || cat $out.pretty
echo
}
function curl_postjs() {
(=<`$9]7<5YXz7wT.3,+O/o'K%$H"'~D|#z@b=`{^Lx8%$Xmrkpohm-kNi;gsedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543s+O<oLm
#!/bin/bash
#
# Set up user-wide:
#
# 1) Copy this file to ~/.git_template/hooks/pre-commit
# 2) git config --global init.templatedir '~/.git_template'
# 3) New repos will initialize from template. Use 'git init' on existing repos to install manually.
#
# Conflict (from https://gist.github.com/danwerner/1006520)
@dln
dln / gist:4761469
Created February 12, 2013 10:35
Sequence comprehension
val t1 = one.getTimestamp
val t2 = other.getTimestamp
if (t1 != null && t2 != null) {
if (t1 < t2) {
one.setValue(other.getValue)
}
}
@dln
dln / dln.xml
Created February 8, 2013 11:29
My color scheme for Intellij IDEA.
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="dln" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.29" />
<option name="EDITOR_FONT_SIZE" value="16" />
<option name="CONSOLE_FONT_NAME" value="Monospaced" />
<option name="CONSOLE_FONT_SIZE" value="11" />
<option name="CONSOLE_LINE_SPACING" value="1.2" />
<option name="EDITOR_QUICK_DOC_FONT_SIZE" value="MEDIUM" />
<option name="EDITOR_FONT_NAME" value="Ubuntu Mono Unhinted" />
<colors>
register /usr/lib/pig/piggybank.jar
-- Data from: http://www.val.se/val/val2010/ledav/nuvarande_ledamoter_RLK.skv
Ledamoter = load 'nuvarande_ledamoter_RLK.skv' using PigStorage(';') as (
valtyp:chararray,
lsnr:chararray,
l:chararray,
kommunnr:chararray,
kommun:chararray,
@dln
dln / CMakeLists.txt
Created October 6, 2012 11:22
Medida Example
cmake_minimum_required (VERSION 2.8.6)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
include(FindPkgConfig)
pkg_check_modules(MEDIDA libmedida)
include_directories(${MEDIDA_INCLUDE_DIRS})
link_directories(${MEDIDA_LIBRARY_DIRS})
add_executable(medida-example1 medida_example1.cc)
package foo.bar;
public class BytesToHex {
public static String bytesToHex(byte[] bytes) {
StringBuilder builder = new StringBuilder();
for (byte b: bytes) {
builder.append(String.format("%02x", b));
}
return builder.toString();
@dln
dln / inotify-cmake.sh
Created July 17, 2012 10:36
Continuous build on the cheap, using inotify, cmake and a terminal
#!/bin/bash
# Watch paths (given as arguments), automatically build when something changes.
# The script does a couple opinionated things to make my life easier:
#
# * Terminal scrollbuffer is reset before each iteration, simplifying scrolling.
# * I use a filter script to colorize gcc output (clang errors would be nicer).
# * Output is copied to a log file (/tmp/build.log).
# - I open this file in Sublime or vim, which reloads the file on change (each build).
#
# Usage: