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
@Tehnix
Tehnix / The journey to unit testing in Python.md
Created August 5, 2013 23:36
A very shallow look at unit testing in python.

With TDD (test driven development) having so much traction in our day and age, I thought it would be highly relevant to explore the concept of unit testing and such.

The idea behind test driven development, is that you first write your tests for your code, and then you write the code. This way, you can constantly watch if the code passes the tests, meaning the implementation is complete. This also forces you to think about your code before you write it, often helping you in visualizing what needs to be done and how.

A little note though, I have limited experience writing actual tests, but do know a bit about the idea/concept behind TDD.

Python gives us the lovely unittest module, which makes unit testing easy. This is, in reality, all you need to get started, but we're gonna get nose, which extends unittest to make testing easier (as is said on their site).

You can install nose via easy_install: easy_install nose

@Tehnix
Tehnix / slight.py
Created August 6, 2013 05:02
Super Light Internal Git Tool (for the lack of better filling for the acronym, slight)...
import sys
import json
import urllib2
import BaseHTTPServer
import SimpleHTTPServer
import subprocess
import threading
#import irc_bot
@Tehnix
Tehnix / mystery_mansion.py
Created November 12, 2013 14:17
Mystery Mansion
"""
The game is called Mystery Mansion.
Simply put, the user has to go through door after door to gain access to the treasure.
Behind every door lurks an evil creature looking for its breakfast, lunch or dinner.
So, all the best.
"""
import random
import datetime
@Tehnix
Tehnix / random_facts.py
Last active December 28, 2015 07:29
Random Facts
from sys import argv
from urllib2 import urlopen
from os.path import exists
URL = "http://numbersapi.com/random"
SCRIPT, TO_FILE = argv
print "Top 5 Facts of The World"
@Tehnix
Tehnix / tehnix_hscms.sh
Created November 24, 2013 12:40
Compile HsCMS and throw it over to keter
#!/bin/bash -ex
cd /home/tehnix/slight/repos/Tehnix/HsCMS
.cabal/bin/cabal-dev clean
.cabal/bin/cabal-dev configure
.cabal/bin/cabal-dev install
.cabal/bin/cabal-dev build
strip dist/build/HsCMS/HsCMS
rm -rf static/tmp/
tar czfv HsCMS.keter dist/build/HsCMS/HsCMS config static
@Tehnix
Tehnix / Foundation.hs
Created November 26, 2013 20:56
Trying to overwrite the loginLayout in yesod 1.2.x
-- Snippet from Foundation.hs
instance YesodAuth App where
type AuthId App = UserId
-- Where to send a user after successful login
loginDest _ = AdminR
-- Where to send a user after logout
logoutDest _ = BlogR
getAuthId creds = runDB $ do
@Tehnix
Tehnix / cabal install helm
Created December 19, 2013 23:00
cabal install helm
tehnix:~/ $ cabal install helm [23:59:27]
Resolving dependencies...
[1 of 2] Compiling SetupWrapper ( /var/folders/7h/vt765h7106723x7p30_jv0680000gn/T/cairo-0.12.5.0-757/cairo-0.12.5.0/SetupWrapper.hs, /var/folders/7h/vt765h7106723x7p30_jv0680000gn/T/cairo-0.12.5.0-757/cairo-0.12.5.0/dist/setup/SetupWrapper.o )
[2 of 2] Compiling Main ( /var/folders/7h/vt765h7106723x7p30_jv0680000gn/T/cairo-0.12.5.0-757/cairo-0.12.5.0/Setup.hs, /var/folders/7h/vt765h7106723x7p30_jv0680000gn/T/cairo-0.12.5.0-757/cairo-0.12.5.0/dist/setup/Main.o )
Linking /var/folders/7h/vt765h7106723x7p30_jv0680000gn/T/cairo-0.12.5.0-757/cairo-0.12.5.0/dist/setup/setup ...
[1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o )
[2 of 2] Compiling Main ( SetupMain.hs, dist/setup-wrapper/Main.o )
Linking dist/setup-wrapper/setup ...
Configuring cairo-0.12.5.0...
Building cairo-0.12.5.0...
@Tehnix
Tehnix / Hamlet $with error.hs
Created January 4, 2014 02:06
Hamlet $with error on ´.´
-- Hamlet file
$with Entity _ user <- runDB $ selectFirst [UserId ==. userId] [] >>= return.fromJust
#{userIdent user}
-- Error (it is referring to the `.` in `return.fromJust`)
<div #content-preview-container>
<div .clear>
" (line 32, column 105):
unexpected '.'
@Tehnix
Tehnix / submitpost.hs
Last active January 2, 2016 23:39
Post Request with Custom Header
import qualified Network.HTTP.Conduit as HTTP
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Network.HTTP.Types.Header as HT
import Data.ByteString.Internal (unpackBytes)
import qualified Data.ByteString.Char8 as C
import GHC.Word (Word8)
testingGist = False
@Tehnix
Tehnix / Foundation.hs
Created January 18, 2014 22:03
Example of combining js and css in the defaultLayout
defaultLayout widget = do
master <- getYesod
mmsg <- getMessage
pc <- widgetToPageContent $ do
$(combineStylesheets 'StaticR
[ css_normalize_css
, css_bootstrap_css
, css_fonts_css
])