Skip to content

Instantly share code, notes, and snippets.

View crankycoder's full-sized avatar

Victor Ng crankycoder

View GitHub Profile
@crankycoder
crankycoder / gist:5554897
Created May 10, 2013 14:52
monitor the existence of a file
import time
def check_file(filename):
try:
with open(filename): pass
return True
except IOError:
return False
def monitor_file():
@crankycoder
crankycoder / gist:5859517
Created June 25, 2013 15:41
When using the go1.1.1 release binary, the Lua sandbox tests fail. This is due to bug https://code.google.com/p/go/issues/detail?id=5726 Patching the Heka Makefile to use the internal linker will reliably reproduce the error.
diff --git a/Makefile b/Makefile
index 0496238..18c68b2 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ build/go:
$(GOBIN): build/go
cd build/go/src && \
- PATH="$(BIN):$(HERE)/pythonVE/bin:$(PATH)" ./all.bash
+ GO_EXTLINK_ENABLED=0 PATH="$(BIN):$(HERE)/pythonVE/bin:$(PATH)" ./all.bash
@crankycoder
crankycoder / gist:6181211
Last active December 20, 2015 19:09 — forked from surrealroad/gist:5146661
Digital Ocean Discourse production install with LAMP (using Apache)
#create & deploy lamp droplet
#login via ssh as root
#initial setup (ref: http://library.linode.com/getting-started#sph_logging-in-for-the-first-time)
# update /etc/hosts (to "thalassophobia.surrealroad.com")
nano /etc/hosts
#
@crankycoder
crankycoder / gist:6302667
Last active December 21, 2015 11:59
Ubuntu Discourse install docs

Official Discourse Install Guide

Recommended Server Hardware

  • 2 GB of RAM
  • 2 GB of swap
  • 2 processor cores

With 2 GB of memory and dual cores, you can run two instances of the thin server (NUM_WEBS=2), and easily host anything but the largest of forums.

@crankycoder
crankycoder / gist:7606664
Created November 22, 2013 20:51
netsyslog.py example
#!/usr/bin/python
import socket
import time
FACILITY = {
'kern': 0, 'user': 1, 'mail': 2, 'daemon': 3,
'auth': 4, 'syslog': 5, 'lpr': 6, 'news': 7,
'uucp': 8, 'cron': 9, 'authpriv': 10, 'ftp': 11,
'local0': 16, 'local1': 17, 'local2': 18, 'local3': 19,
@crankycoder
crankycoder / gist:7606676
Created November 22, 2013 20:52
TOML config to debug syslog over UDP problems
[UdpInput]
address = "127.0.0.1:2514"
parser_type = "packet"
decoder = "syslog_sandbox"
[syslog_sandbox]
type = "SandboxDecoder"
script_type = "lua"
filename = "/tmp/syslog_decoder.lua"
timestamp_field = "syslog_ts"
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
-- Original grok filters
-- POSINT \b(?:[0-9]+)\b
-- GREEDYDATA .*
-- HOUR (?:2[0123]|[01][0-9])
-- MINUTE (?:[0-5][0-9])
-- SECOND (?:(?:[0-5][0-9]|60)(?:[.,][0-9]+)?)

Save books out of Safari Books Online

From http://objectivesea.tumblr.com/post/9033067018/safaribooks

This is hard. I spent way too much time figuring this out, because I was annoyed that a book I bought (Addison-Wesley) was available online for free, except only for 45 days after which payment was required. So I made this hack... probably useful to no one else, but here it is.

Requirements:

  1. iPad.
  2. Safari To Go (the Safari Books Online iPad app).
@crankycoder
crankycoder / gist:34d11a9f8202a10f3adb
Created October 1, 2014 23:35
Bootstrap Ubuntu 14.04 into a workable MozStumbler buildbox
#!/bin/sh
sudo apt-get -qqy update
sudo apt-get install -y unzip git make openjdk-7-jdk
# Everybody loves that android needs x86 stuff
sudo dpkg --add-architecture i386
sudo apt-get -qqy install libncurses5:i386 libstdc++6:i386 zlib1g:i386
@crankycoder
crankycoder / building-static-nginx.txt
Created May 26, 2016 01:36 — forked from rjeczalik/building-static-nginx.txt
Notes on building nginx as a static binary.
# Building static nginx for teh lulz
#
# basic dependencies
sudo apt-get install libxslt1-dev libxml2-dev zlib1g-dev libpcre3-dev libbz2-dev libssl-dev
# download nginx and openssl
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar xf nginx-1.5.6.tar.gz; cd nginx-1.5.6