Skip to content

Instantly share code, notes, and snippets.

View sprin's full-sized avatar

Steffen Prince sprin

  • Medellín, Colombia
View GitHub Profile
# Vagrant commands
vagrant reload #!
vagrant status
vagrant suspend
vagrant resume
vagrant halt
vagrant up
vagrant package
vagrant destroy
vagrant box add <nombre> <url>
@sprin
sprin / Dockerfile
Created August 12, 2014 00:11
Python 2.7.8 on Centos 5
FROM tianon/centos:5.8
RUN yum install -y curl tar gcc make xz
RUN mkdir /usr/src/python
WORKDIR /usr/src/python
RUN curl -Sl "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz" > Python-2.7.8.tar.xz
RUN xz -dc < Python-2.7.8.tar.xz > Python-2.7.8.tar
RUN tar -xvf Python-2.7.8.tar -C /usr/src/python --strip-components=1
# You may want to verify the download with gpg: https://www.python.org/download
@sprin
sprin / Dockerfile
Created August 12, 2014 00:08
Python 2.7.8 on Centos 5
FROM tianon/centos:5.8
RUN yum install -y curl tar gcc make xz
RUN mkdir /usr/src/python
WORKDIR /usr/src/python
RUN curl -Sl "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz" > Python-2.7.8.tar.xz
RUN xz -dc < Python-2.7.8.tar.xz > Python-2.7.8.tar
RUN tar -xvf Python-2.7.8.tar -C /usr/src/python --strip-components=1
# You may want to verify the download with gpg: https://www.python.org/download
@sprin
sprin / ansible_module_syntax.yml
Last active August 29, 2015 14:04
ansible module argument syntax?
---
# Do this?
- name: create droplet 512MB/Centos 7/Region NYC2
digital_ocean: >
command=droplet
state=present
name={{ droplet_name }}
client_id={{ client_id }}
api_key={{ api_key }}
size_id=66
@sprin
sprin / closures.py
Last active August 29, 2015 14:04
Python "closures"
"""
A little demo of some of the quirks of Python "closures" with inner functions.
Function closures allow a function to access nonlocal variables in the
enclosing scope, even when invoked outside it's immediate lexical scope.
In languages centered around mutable data types, you would expect to be
able to mutate nonlocals in a closure.
MDN has an excellent rundown of closures, with examples in Javascript.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures

Installation

FreeBSD

portmaster irc/irssi
portmaster irc/irssi-xmpp

OS X

brew install irssi

@sprin
sprin / calling_patterns.py
Created July 10, 2014 17:36
Safe and unsafe Python function calling patterns
"""
A demonstration of safe and unsafe ways to write and call Python functions that
take required and optional arguments that are likely to change over time.
Try performing common refactoring operations on the functions such
as adding/removing required/optional args and changing args to and from
required to optional. Also consider combinations of these operations.
The calling patterns marked dangerous are likely to break in some of these
situations, whereas the safe pattern of always calling with keywords
from flask import Flask
app = Flask(__name__)
import datetime
from threading import local
threadlocal = local()
@app.route('/')
@sprin
sprin / threadlocal_abuse.py
Last active August 29, 2015 13:56
Thread Locals Abuse
from threading import local
threadlocal = local()
# foo takes a as an arg, but we can also see it is dependent on x from
# threadlocal if we look in the body.
def foo(a):
return a + threadlocal.x
# bar takes a as an arg, and calls foo on it. Unless we read through the
@sprin
sprin / gist:8643219
Created January 27, 2014 04:18
Backbone VisEventsView
var VisEventsView = Backbone.View.extend({
// A Backbone.View extension that allows a View to trigger events when
// it's visibility changes. The view may also listen to its own visibility
// events.
setup_visibility_observer: function() {
// Check if view element is visible when attributes of el change.
var t = this;
_.bindAll(t, 'check_visibility');
t.visibility_observer = new MutationObserver(t.check_visibility);