Skip to content

Instantly share code, notes, and snippets.

import sys
with open(sys.argv[1]) as source, open('ln_' + sys.argv[1], 'w') as target:
for i, line in enumerate(source):
target.write('{:02d}{}'.format(i,line[2:]))
@behrtam
behrtam / htwaib_finalgrade.py
Created August 3, 2015 13:57
HTW AI Bachelor – Berechnung des Gesamtprädikats
#!/usr/bin/env python
# coding: utf8
from __future__ import print_function
'''
HTW AI Bachelor
§9 Berechnung des Gesamtprädikats
http://ai-bachelor.htw-berlin.de/fileadmin/HTW/Alle/Amtliche_Mitteilungsblaetter/2012/30_12.pdf
'''
#!/bin/sh
BVG_CLI_CLIENT_URL="https://raw.githubusercontent.com/behrtam/bvg-cli/master/bvg_cli.py"
BVG_CLI_REQUIREMENTS_URL="https://raw.githubusercontent.com/behrtam/bvg-cli/master/requirements.txt"
echo "BVG CLI – Installation"
cd /usr/local/bin/
rm bvg_cli.py
@behrtam
behrtam / caseless_assertions.py
Created November 21, 2015 10:23
Add support for caseless assertions that also work with unicode through mixin.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
import unicodedata
''' There is text for which text.lower() != text.upper().lower(), such as "ß":
"ß".lower()
#>>> 'ß'
@behrtam
behrtam / asserttest.py
Created November 25, 2015 22:12
"This method is used by default when comparing strings with assertEqual()." https://docs.python.org/2/library/unittest.html?highlight=unittest#unittest.TestCase.assertMultiLineEqual
import unittest
class AssertTests(unittest.TestCase):
def testAssertEqual(self):
self.assertEqual('ABCD', 'ABC')
def testAssertMultiLineEqual(self):
self.assertMultiLineEqual('ABCD', 'ABC')
if __name__ == '__main__':
@behrtam
behrtam / tuple_add_bench.py
Created November 26, 2015 07:53
Let's find out what's the fastest way to add tuple. http://exercism.io/submissions/a508c287053f48cbb9e3754ebcf3346c
'''
Test performance of tuple adding on Macbook Air 2012:
unpacking : 1,598 min | 2,136 max | 1,787 avg (µs)
index : 2,622 min | 5,016 max | 3,402 avg (µs)
map add : 7,849 min | 10,670 max | 8,886 avg (µs)
map sum zip : 11,254 min | 16,354 max | 12,854 avg (µs)
'''
import timeit
def show_result(func, result):
@behrtam
behrtam / caesar.c
Last active December 14, 2015 16:29 — forked from haup/caesar.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char* string;
string encrypt(int offset, string text);
string decrypt(int offset, string text);
/* Programmaufruf: ceasar [-d|-e] [offset] [text ...]
@behrtam
behrtam / SConstruct
Created November 3, 2013 10:46
Instead of writing down the needed cpp-files manually, it just takes all the cpp-files of the current directory.
"""
This Auto-SConstruct takes alle *.cpp files of the current directory - the directory the SContruct is placed in.
The program name is based on the name of a file ending with '_main.cpp'.
Example: 'myprog_main.cpp' -> 'myprog'
If there is a file eding with '_test.cpp' a google testprogram is compiled with a similar naming process.
Example: 'mytest_main.cpp' -> 'mytest'
author: Tammo Behrends (2013)
const md5 = require('md5')
let door_id = 'ugkcyxxp'
let password = '--------'.split``
let index = 0
let found = 0
while (found < 8) {
let hash = md5(`${door_id}${index}`)
@behrtam
behrtam / ber_kultur.md
Last active April 18, 2017 09:01
Kultur in Berlin vom 14. – 16.04.

AUSSTELLUNGEN

VERLOREN IN BERLIN UND BUKAREST

eine Ausstellung über das Leben jugendlicher auf der Strasse

WANN: 16. März bis 21. Mai 2017, Dienstag bis Sonntag 12 bis 18 Uhr WO: Willy-Brandt-Haus WIE VIEL: Der Eintritt ist frei.

  • mehr