Skip to content

Instantly share code, notes, and snippets.

@reinhrst
reinhrst / gist:2000430
Created March 8, 2012 10:59
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Symbol

When doing lein compile or lein jar, I ran into this error. While at the same time lein run worked fine (at least most of the time...)

#~/foo 11:51:59 > lein jar
Compiling foo.core
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Symbol
at clojure.core$find_ns.invoke(core.clj:3657)
at clojure.core$load_one.invoke(core.clj:5201)
at clojure.core$compile$fn__4615.invoke(core.clj:5397)
at clojure.core$compile.invoke(core.clj:5396)
@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 / dct.c
Created March 20, 2012 19:46
DCT-II implementation using the vDSP on the iOS (and also OSX?)
/* This implementation does DCT-II on iOS, using the iOS vDSP FFT methods. Supposedly this is faster than in plain C (i.e. FFTW), but I didn't do any tests to support this claim. For one thing, as far as I understand it, doing DCT takes less clock cycles than FFT, and using this code we do an FFT of size 2N for a DCT of size N (and then some post processing. Anyone is welcome to comment :)
This code was developed using the following 2 sources, and I owe great gratitude to their authors: http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/vDSP_Programming_Guide/UsingFourierTransforms/UsingFourierTransforms.html and http://www.hydrogenaudio.org/forums//lofiversion/index.php/t39574.html
I don't claim I understand everything I do, but the thing is, it works -- as in, it gives me the same result as jtransform with scaling on :) And it's fast enough for my use: on the iPhone 4S I can get 320 DCTs of length 2048 per second. Perhaps I can improve this with some further tweaking (although I'
@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 / epylint.py
Created June 6, 2012 09:51
epylint -- use pylint with emacs, with google app engine in path
#!/usr/bin/env python
import re
import sys
from subprocess import *
PYTHONPATH = check_output('/usr/bin/find /Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/ -depth 1 -type d -exec /bin/echo -n "{}:" \;', shell=True)
PYTHONPATH += '/Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/';
p = Popen(["/usr/local/bin/pylint","-fparseable","-rn","--disable=C,R",
@reinhrst
reinhrst / gist:2909594
Created June 11, 2012 11:01
Trick to use (window.innerWidth - #variable#) properties in css
/**
* allows the kind of css rules in your stylesheets that you always wanted:
* #bottom_bar {bottom: 0px; top: window.innerHeight - 50px}
* (obviously one could use height: 50px in this case, but I want to animate on the top property)
* This code (currently only tested on webkit) allows "magic values" for properties: 314151 means "width minus", 314152 means "height minus"
* #bottom_bar {bottom: 0px; top: 31415250px} // this results in the desired behaviour
* Note: only run this function after all the stylesheets have been loaded (or rerun after load of a new stylesheet)
**/
var STYLEMAGIC_WIDTH_MINUS = /^314151(\d+)(\w+)$/;
@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;