Skip to content

Instantly share code, notes, and snippets.

@reinhrst
reinhrst / campfirestatus.py
Last active August 29, 2015 14:08
Proof of concept for Buildbot 0.89 / Campfire integration. For sure makes some assumptions on our buildbot setup!
import base64
from twisted.internet import reactor
from buildbot.interfaces import IStatusReceiver
from twisted.application import service
from twisted.web.client import getPage
from zope.interface import implements
from twisted.internet import defer
import httpstream
import json
@reinhrst
reinhrst / tutorial.md
Last active August 29, 2015 14:17
Ecmascript 6+: Babel + Webpack for the browser and serverside (without flowtype, but with sourcemaps).

NOTE: code accompanying this text [here][11].

After [my initial flirting with some advanced python][2] for the backend at Lone Rooftop, in the end we decided to go all-in on the nodejs trail. There are a number of reasons for this.

  1. Even though it's quite doable to keep two languages in one's head, python for server-side, and javascript client-side, I do still notice that I mix them up (answer quickly: how to add an element to a python list? And how to a javascript array?). And wouldn't it be better to only have to keep one in one's head (and use the saved brain-space to keep more of the application in there)?
  2. Like any developer I spened a lot of time setting up my editor (in my case vim) in just the way I like it. It's probably better to only have to do this once, for one language, then having to do this twice. And personally I don't believe in editors that come fully set-up.... In the end there is always some small thing that I'd like to change.
  3. Even though the two points above are minor nuisanc
@reinhrst
reinhrst / .vimrc
Created August 23, 2015 21:09
Vim function to quickly toggle between dict notation `a["x"]` and dot notation `a.x`. Uses vim-repeat in the end, to enable repeat
function DictDotToggle()
python << endpython
import re, vim
(row, col) = vim.current.window.cursor
line = vim.current.buffer[row - 1]
re_word = "(?P<word>[a-zA-Z_][a-zA-Z0-9_]*)"
dottedwords = re.finditer(r"\." + re_word, line)
for dottedword in dottedwords:
if dottedword.start("word") <= col and dottedword.end("word") > col:
new_line = (
@reinhrst
reinhrst / gist:2040625
Created March 15, 2012 00:14
Mar 15 00:54:47 unknown mediaserverd[43] <Error>: 00:54:47.702 <0x2745000> AURemoteIO::ChangeHardwareFormats: error -10875 using AVCaptureAudioDataOutput

OK, so I am new to IPhone development, but I guess this is an error I won't be making any more!

In iOS 5.1, this code should have printed a lot of "Yeah, we've got something"'s... But in stead, all I got was Mar 15 00:54:47 unknown mediaserverd[43] <Error>: 00:54:47.702 <0x2745000> AURemoteIO::ChangeHardwareFormats: error -10875

- (void)viewDidLoad
{
  [super viewDidLoad];

  AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];

@reinhrst
reinhrst / add-timestamps.sh
Created March 27, 2012 00:29
Each line of output is preceded by a timestamp. The timestamp is printed as soon as the first character on the newline is produced
#!/bin/bash
WASNL=1;
NL="$(/bin/echo)";
while [[ true ]]; do
IFS= read -r -n 1 C;
if [ $WASNL -eq 1 ]; then
/bin/echo -n $(date "+%Y-%m-%d %H:%M:%S") "";
fi;
@reinhrst
reinhrst / lazy-or
Created March 27, 2012 23:28
lazy-or macro. Only evaluates contents as long as they return falsy, returns the first truthy value
(defmacro lazy-or [& block]
(case (count block)
0 nil
1 (first block)
`(if-let [result# ~(first block)]
result#
(lazy-or ~@(rest block)))))
@reinhrst
reinhrst / README
Created June 4, 2012 22:56
Hello world of clojure + compojure + google app engine (smallest working set)
NOTE: colons in file names are directory separators (which are not allowed in gist...)
NOTE2: Actually it doesn't like colons either, so all files are here twice now and I can't remove them.... Have fun with them :)
NOTE3: Very likely the appengine dependency is not even needed. Doesn't hurt though and is most likely useful later....
These 4 files will make a project that runs on appengine.
To run:
lein dep
lein compile
@reinhrst
reinhrst / gist:2933815
Created June 15, 2012 00:23
Webkit CSS: fade in and out

I was looking for a CSS-only solution to fade a page overlay in and out. Obviously this should do the trick:

#loadingIndicator {position: absolute, z-index: 1;  opacity: 0; -webkit-transition: opacity 2s; }
body.loading #appLoadingIndicator { opacity: 0.8; }

However, this leaves an invisible layer on top of everything, which catches all clicks or other mouse events. This problem seems to have come up more often (http://stackoverflow.com/questions/4178567/webkit-transition-with-display). The solution is to use a transition on 2 properties, and move the layer out of the way after it has faded out:

#loadingIndicator {position: absolute, z-index: 1;  top: -1000px; opacity: 0.2; -webkit-transition-property: opacity, top; -webkit-transition-duration: 2s,0; -webkit-transition-delay: 0, 2s; }
body.loading #appLoadingIndicator { opacity: 0.8; top: 0; -webkit-transition-delay: 0,0;}
var enableChildTracking = function (Klass) {
var old_extend = Klass.extend;
Klass.__children = [];
Klass.extend = function () {
var That = this;
var result = old_extend.apply(That, arguments);
That.__children.push(result);
result.__children = [];
return result;
@reinhrst
reinhrst / dates.sh
Last active November 8, 2015 11:57
#!/bin/bash
# oneliner to print a range of dates, ending today
for i in $(seq -f %.0f $(date -j -f %Y-%m-%d 2015-10-15 +%s) $((24 * 60 * 60)) $(date +%s)); do date -jf %s $i +%Y-%m-%d; done
# and one in python
python -c "import datetime; date = datetime.date(2015, 10, 5); days = range((datetime.date.today() - date).days); print(' '.join(str(date + datetime.timedelta(day)) for day in days))"