Skip to content

Instantly share code, notes, and snippets.

View preview_decorator.py
def add_preview_for(*fields):
"""
This is a decorator for model classes that adds preview methods.
So instead of manually adding preview methods:
>>> class Student(models.Model):
... photo = models.ImageField()
... icon = models.ImageField()
...
@shamrin
shamrin / Makefile
Last active Aug 29, 2015
UmTRX GPS NMEA
View Makefile
# this makes sure libraries are installed and up-to-date (with requirements.txt)
venv: venv/bin/activate
venv/bin/activate: requirements.txt
test -d venv || virtualenv venv
. venv/bin/activate && pip install -Ur requirements.txt
touch venv/bin/activate
View README.md
$ rm -f test.sqlite && python bug_models.py create && python bug_add.py && echo '.schema' | sqlite3 test.sqlite
CREATE TABLE "device" ("id" INTEGER NOT NULL PRIMARY KEY, "name" VARCHAR(20) NOT NULL, "owner_id" INTEGER, "network_id" INTEGER, FOREIGN KEY ("owner_id") REFERENCES "user" ("id"));
CREATE TABLE "network" ("id" INTEGER NOT NULL PRIMARY KEY, "name" TEXT NOT NULL);
CREATE TABLE "user" ("id" INTEGER NOT NULL PRIMARY KEY, "full_name" VARCHAR(128) NOT NULL);
CREATE INDEX "device_network_id" ON "device" ("network_id");
CREATE INDEX "device_owner_id" ON "device" ("owner_id");

$ rm -f test.sqlite && python bug_models.py create && python bug_drop.py
…
peewee.OperationalError: unknown column "owner_id" in foreign key definition
@shamrin
shamrin / env.fish
Last active Aug 29, 2015
env that also supports fish functions, see https://github.com/fish-shell/fish-shell/issues/438
View env.fish
# `env` that also supports fish functions
function env
set -l vars
set -l vals
set -l save_vars
set -l save_vals
set -l save_empty_vars
# parse var=val pairs into `vars` and `vals` arrays
set -l n 1
@shamrin
shamrin / My LightTable problems.md
Last active Aug 29, 2015
Issues that prevent me from switching to LightTable
View My LightTable problems.md

Absolute blockers:

  • Vim#13 - * search state
  • Vim#43 - no auto-repeat (connected to Vim#8 - see below)
  • Vim#44 - invisible cursor (there's a workaround)
  • bad color scheme (connected to issue above)

Problems that prevent me from using special LightTable features

  • JS#10 (I've made [a fix][1])
@shamrin
shamrin / 0README.md
Last active Mar 29, 2020
Install OsmoNITB with SMPP
View 0README.md

Quick Osmocom OpenBSC installation

Prerequisites

  • Ubuntu Trusty (previous LTS and in between versions should work too)
  • sudo apt-get install gcc make git autoconf libtool pkg-config build-essential automake libortp-dev python libsqlite3-dev

Installing

View gauge.js
function Gauge(placeholderName, configuration)
{
this.placeholderName = placeholderName;
var self = this; // for internal d3 functions
this.configure = function(configuration)
{
this.config = configuration;
View gist:9692625
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "root@ubuntu.(none)" ]
View gist:7224865

I've deployed private Docker registry under reverse proxying nginx (with basic auth). But pushing to it doesn't work:

$ docker push my-server.com/repo
2013/10/29 23:58:08 Invalid Registry endpoint: This does not look like a Registry server ("X-Docker-Registry-Version" header not found in the response)

Testing the server with curl:

$ curl -i --user me:password my-server.com | grep X-Docker
X-Docker-Registry-Version: 0.6.2
X-Docker-Registry-Config: dev