Skip to content

Instantly share code, notes, and snippets.

View mbertheau's full-sized avatar

Markus Bertheau mbertheau

View GitHub Profile
/*
* cc -o main main.c -lreadline
*/
#include "readline/readline.h"
int main(int argc, const char* argv)
{
char *line;
while (1) {
set_of_lines = SetOfLines([])
stock_info = basket.strategy.fetch_for_product(product)
new_line_ref = object()
set_of_lines.add_line(Line(new_line_ref, product, stock_info.stockrecord, 1,
stock_info.price.incl_tax))
applicator = Applicator()
offers = applicator.get_offers(request, basket)
applicator.apply_offers(set_of_lines, offers, request.user)
@mbertheau
mbertheau / hangul-reading.rkt
Last active August 29, 2015 14:13
Learning racket
#lang racket
(define hangul-data-file "src/racket-unihan/Unihan_Readings.txt")
(define (port-filter predicate)
(define next-line
(lambda (in)
(define l (read-line in))
(if (or (eof-object? l)
(predicate l))
@mbertheau
mbertheau / gist:824e23a31b58624daf31
Created January 22, 2015 15:00
hubot cron not working
CronJob = require('cron').CronJob
new CronJob('* * * * * *', () ->
console.log "tick"
return
, null, true, "Europe/Berlin")
module.exports = (robot) ->
tz = 'Europe/Berlin'
new CronJob('* * * * * *', testBuild, null, true, tz)
@mbertheau
mbertheau / gist:bc22d6a8155cb9dd3480
Created February 9, 2015 13:02
assert assertInHTML('a', '<span>a</span>') == True
from django.test.testcases import SimpleTestCase
class A(SimpleTestCase):
def f(self):
self.assertInHTML('a', '<span>a</span>')
def runTest(self):
pass
a = A()
@mbertheau
mbertheau / fizzbuzz.rkt
Last active August 29, 2015 14:20
Learning Racket - some fizzbuzzing
#lang racket
(define (fizzbuzz)
(for/list ([n (in-range 1 101)])
(let ([fizz (zero? (remainder n 3))]
[buzz (zero? (remainder n 5))])
(cond [(and fizz buzz) "FizzBuzz"]
[fizz "Fizz"]
[buzz "Buzz"]
[else (number->string n)]))))
@mbertheau
mbertheau / example.py
Created August 30, 2015 13:53
What's this in clojure?
def add_net_and_tax(discounts):
discounts = map(lambda discount: assoc(discount, 'net', round(discount['gross'] / (1 + tax_rate))),
discounts)
discounts = map(lambda discount: assoc(discount, 'tax', discount['gross'] - discount['net']),
discounts)
return discounts
(defn progress-visualization:c [normal-progress overtime-progress text]
(let [normal-bar [:div.progress-bar.progress-bar-success
(let [base-style {:style {:width (str normal-progress "%")}}
final-style (if overtime-progress
base-style
(assoc base-style :class "progress-bar-striped"))]
final-style) text]]
(if overtime-progress
[normal-bar
[:div.progress-bar.progress-bar-warning.progress-bar-striped
@mbertheau
mbertheau / handler_macros.clj
Last active September 22, 2015 14:46
My first macro
(defmacro defhandler
[handler-name argv body]
`(re-frame.core/register-handler
~(keyword (name handler-name))
(comp re-frame.core/debug re-frame.core/trim-v)
(fn ~(if (> (count argv) 1)
(vec (list (first argv) (vec (rest argv))))
argv)
~body)))
(defn weekdays []
(let [weekdays-ratom {:mon {:takes-place? true :times ["9:00" "10:30"]}
:tue {:takes-place? false}
:wed {:takes-place? false}
:thu {:takes-place? false}
:fri {:takes-place? false}
:sat {:takes-place? false}
:sun {:takes-place? false}}
names {:mon {:intro "und zwar jeden" :word "Montag"}
:tue {:intro "und jeden" :word "Dienstag"}