Skip to content

Instantly share code, notes, and snippets.

View emilisto's full-sized avatar

Emil Stenqvist emilisto

  • Stockholm
View GitHub Profile
@emilisto
emilisto / js-prototype-play.js
Created August 27, 2013 13:38
Some code I wrote to understand the pattern @jashkenas uses to setup the prototype chain in Backbone and Underscore.
var _ = require('underscore');
function printPrototypeChain(instance, asArray) {
var chain = []
while (instance = Object.getPrototypeOf(instance)) {
var name = instance.constructor.toString().match(/f.+n (.+)\(/);
chain.push(name && name[1]? name[1] : "(anonymous function expression)")
}
return asArray? chain : chain.join(" -> ")
}
@emilisto
emilisto / interact.py
Created August 16, 2013 11:10
A little tool I came up with to be able to quickly work with API's I'm unfamiliar with. Just call `inspect()` anywhere in the code and you'll get an interactive prompt where you can interact with all variables, see their attributes, methods etc.
import bpython
import inspect
def interact():
"""
Just run interace() anywhere in your code, and you'll get a sweet
interactive bpython interpreter with access to the scope of where you
called it. Great for investigating new API's.
"""
try:
{
"variables": {
"salt_role": "common"
},
"provisioners": [
{
"type": "shell",
"scripts": [
"scripts/ec2-ephemeral-tmp.sh"
],
// We assume that this is running in an iframe which loads a page from a domain
// that is specific to where your widget is served from. This means that for
// browsers that support 3rd party cookies in iframes, the cookie will be set
// on this domain, and for those who don't, localStorage will be used instead.
ga('create', 'UA-XXXX-Y', {
'storage': 'none',
'clientId', getPersistentVisitorId()
});
/*
* @getPersistentVisitorId: Generates a unique visitor ID that is persisted between visits.
*
* We assume we're in an iframe, so for Safari users we use localStorage,
* and for everyone we use local domain cookies.
*/
var getPersistentVisitorId = (function() {
var key = 'silp_visitorid';
var method = allowsThirdPartyCookies() ? 'cookie' : 'localStorage';
var persistor = {
@emilisto
emilisto / retry.sh
Last active December 20, 2015 03:19
Little bash script that re-runs a command until it exits with code 0, i.e. runs successfully. I get impatient when SSH'ing to new servers...
#!/bin/bash
# Examples:
#
# When's the damn thing online?
#
# $ retry.sh ssh [email protected]
#
# When's internet back?
#
@emilisto
emilisto / ec2_tags.py
Last active March 15, 2019 17:07
Grain for Salt that exposes all EC2 instance tags in grains['tags'], free for all to use and distribute. Tweet me @svammel if you have questions.
"""
ec2_tags - Exports all EC2 tags in a 'tags' grain
For Salt (http://saltstack.org)
Author: Emil Stenqvist <[email protected]>
Usage:
1. Put ec2_tags.py in roots/_grains/
## lib.sls
# Shorthand macro for getting pillar data
{% macro p(key, default='') -%}
{{ salt['pillar.get'](key, default) }}
{%- endmacro %}
## Usage
{% from 'lib.sls' import p with context %}
{{ p('git:url', '[email protected]') }}
@emilisto
emilisto / config.js
Last active December 19, 2015 01:19
Installing Graphite on Ubuntu 12.10. Sadly, it's 2013, and this is the quickest procedure I could come up with. Special criticism goes out to the packaging of Graphite, Carbon and pycairo. Anyhow, see the `install.sh`, it's meant to read as copy-think-and-paste instructions.
{
graphitePort: 2003,
graphiteHost: "localhost",
port: 8125,
backends: [ "./backends/graphite" ]
}

Mathias

There are actually two different ways of achieving concurrency in Go:

Nice format:

import (
  "fmt"
)