I am Magnus Lidström. I write code. Lots of it. Some of it ends up at
soniccharge.com. Some of it ends up here. Most of it ends up in ~/Trash.
October 29, 2014
I have always wanted the input and output text in the OS X Terminal to be in different colors. Unfortunately no such setting exists in Terminal itself but through some clever Bash tricks one can achieve the next best thing: different colors for prompt, command line and program I/O. For example: The idea is to inject ANSI color sequences in the $PS1 prompt string and use a trap to change the color back before commands are executed. I base my implementation on this post. Here are the lines that I have put into my .profile: PS1="\[\e[0;33m\]\h \w$ \[\e[0m\]" debug() { echo -n $'\e[0;32m';
October 16, 2014
PikaScript is a small interpreting C-style scripting language implemented with modern C++ programming techniques (C++03). The source code for PikaScript is very compact. It's core is around 1000 lines of C++ plus an additional header file of 500 lines including doxygen comments. The optional standard library (written in PikaScript), providing utilities for strings, math, algorithms and objects (including a mark and swipe garbage collector) is around 300 lines of source code Despite it's small size the language is powerful enough to support sophisticated concepts such as higher order functions
June 01, 2014
Symbiosis is a developer tool for adapting Mac OS X VST plug-ins to the Audio Unit (AU) standard. It essentially consists of a single C++ file that you can compile into your VST project to make the plug-in compatible with the Audio Unit protocol. Optionally, you may choose to use a pre-built "wrapper plug-in" for adapting your existing VST plug-in to the AU standard without even having to recompile any source code. How Does It Work? Although the VST and Audio Unit SDKs differ greatly in implementation, the purpose and functions of the two standards are virtually identical. Both protocols p
June 01, 2014
Here is the tiniest recursive algorithm I could come up with to perform string matching with DOS-like wildcard support. Let me know if you find any simpler implementation. bool wildcardMatch(const char* p, const char* s) { while (*p != '\0') { if (*p == '*') { if (wildcardMatch(p + 1, s)) { return true; } } else if (*p == '?' || tolower(*p) == tolower(*s)) { ++p; } else { return false; } ++s; } return (*s == '\0'); } p is pattern to match (? matches any character, * matches a
June 01, 2014
Priyome is a complete chess computer in single plain C source code file. It was written to be easily ported to other even more primitive languages. E.g. it uses only integers and does not require structures. The AI is implemented using standard chess computer techniques such as alpha beta pruning search with iterative deepening, quiescence optimization (only checking for captures beyond a specific depth) and a memory efficient solution for transposition table lookup. A B C D E F G H +-----------------+ 8 | r n b q k b n r | 8 7 | p p p p p p p p | 7 6 | . . . . | 6 5 | . . .