Skip to content

Instantly share code, notes, and snippets.

View Tehnix's full-sized avatar
🌞
Enjoying the code...

Christian Kjær Tehnix

🌞
Enjoying the code...
View GitHub Profile
$(document).ready(function() {
var githubDir = {
__name__: 'github',
Tehnix: {
__name__: 'Tehnix'
},
ZealDev: {
__name__: 'ZealDev'
}
};
@Tehnix
Tehnix / isPrime.py
Created October 17, 2012 20:58
Comparing primality checking functions
"""
Compare different methods of checking for a numbers primality.
"""
import math
import time
import sys
def isPrime(n):
@Tehnix
Tehnix / SystemTrayIcon.py
Created January 13, 2013 23:56
Toying with getting an icon in the system tray on OS X
import sys
import wx
TRAY_TOOLTIP = 'System Tray Demo'
TRAY_ICON = 'dropboxstatus-idle.ico'
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.AppendItem(item)
@Tehnix
Tehnix / PyObjc System Icon.py
Created January 14, 2013 11:43
A quick example of showing a tray icon using the pyobjc bindings (OS X)
import objc, re, os
from Foundation import *
from AppKit import *
from PyObjCTools import NibClassBuilder, AppHelper
# poach one of the iSync internal images to get things rolling
status_images = {'idle':'/Users/tehnix/Desktop/dropboxstatus-pause-lep.png'}
start_time = NSDate.date()
@Tehnix
Tehnix / lstlisting.tex
Last active December 15, 2015 17:09
Latex lstlisting settings.
\lstset{
breaklines=true,
xleftmargin=25pt,
xrightmargin=25pt,
aboveskip=10pt,
belowskip=10pt,
basicstyle=\ttfamily,
backgroundcolor=\color{lightlightgray},
showstringspaces=false,
frame=ltrb,
@Tehnix
Tehnix / startHsIRCb.sh
Last active December 16, 2015 10:59
To deploy HsIRCb with jenkins. Clean/Configure/Install/Build with cabal-dev, and then start the program.
#!/bin/bash -ex
cd $WORKSPACE
PID_FILENAME="$WORKSPACE/HsIRCb.pid"
LOG_FILENAME="$WORKSPACE/HsIRCb.log"
touch $PID_FILENAME # Make sure the pid file exists
PID=$(cat $PID_FILENAME)
if kill -0 $PID > /dev/null 2>&1; then
# The program is running
#kill $PID
daemon --name=HsIRCb --stop
@Tehnix
Tehnix / list_filter_benchmark.py
Last active December 20, 2015 07:59
Benchmarking of several list construction methods with filtering applied.
import time
import itertools
def test_results(tests, times_to_run_tests, *args):
# Fetch the results and save the value of the fastest function
fastest = None
results = []
for fn in tests:
name = ""
res = 0
@Tehnix
Tehnix / Notification alerts from irssi (and keeping ssh connection alive).md
Last active December 20, 2015 16:19
Get local notification alerts from irssi on a remote server, and use autossh to keep the ssh connection alive after connection loss.

Local notification alerts from irssi on a remote server (and keep the ssh connection alive after connection loss)

First of all, thanks to prebenlm for making his walkthrough Irssi in Mac OS X Notification Center.

This is made with OS X in mind, but, should be easily transported over to other systems. Just use another notification system instead of the Apple Notification center and terminal-notifier (and you'll also have to workout the auto launch of the scripts yourself)...

Programs you'll need

  1. autossh
  2. terminal-notifier
@Tehnix
Tehnix / Automatization and Media Server.md
Created August 5, 2013 23:28
Automatization and Media Server using Plex and Sick-Beard with the ThePirateBay branch from mr-orange.

Automatization and Media Server

So, recently I've been thinking about what to do with an old white Macbook I had lying around. Then I thought, what could I automate in my life that I'm doing manually now, and it struck me, I watch a lot of series. So, I started looking around for a good PVR and stumpled upon Sickbeard, but the thing is, I'm not so super happy about paying for a Usenet membership (especially since I was just playing around atm). I succeeded in finding a fork/branch that supported using torrents instead of NZB.

Torrent branch of Sickbeard

Following this forum post, since I had all the prerequisits I only needed to clone down the repo and set it up for use with Transmission (my torrent program). If you wanna autostart Sickbeard on launch and you're on OS X like me you can follow these instructions to make an

@Tehnix
Tehnix / CloudFlare API.md
Created August 5, 2013 23:34
A simple look at the cloudflare API with python.

Since we, and a lot of other people, are using CloudFlare for optimization reasons (aka, the easy way out), I thought I would take a look at their API. First thing I looked for was how to purge the cache from command line.

Now, if you don't know why I'd want to do this, let me explain. We have setup codetalk.io as a Django project, with nginx running fastcgi passing it through on localhost which Django is listening to and then responds accordingly.

Now, we usually make some changes here and there, styles and structuring. One of the things CloudFlare does for us, is cache some of our content, mainly CSS and JS. Caching, in this case, means that instead of the request coming all the way down to our server to get the file, it is picked up by CloudFlare that has set a cache time for it sparing us the load of serving it again and again (if you know varnish, they kindda act like a varnish proxy in front of us).

So, CloudFlare needs to know when we have updated our content so it can purge the cache and begin asse