Skip to content

Instantly share code, notes, and snippets.

View quarnster's full-sized avatar

Fredrik Ehnbom quarnster

  • Stockholm, Sweden
View GitHub Profile
@quarnster
quarnster / dreamcast.toolchain.cmake
Created July 28, 2012 07:05
Dreamcast cmake toolchain
# This has been working pretty well for me with:
# export KOS_CFLAGS="-Wa,--isa=sh4 -fomit-frame-pointer"
# export KOS_AFLAGS="--isa=sh4"
# . ${KOS_BASE}/environ_base.sh
# cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/dreamcast.cmake.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER kos-cc)
set(CMAKE_CXX_COMPILER kos-c++)
set(CMAKE_ASM_COMPILER kos-as)
set(CMAKE_LINKER kos-cc)
@quarnster
quarnster / gist:3238415
Created August 2, 2012 16:32
AngelScript preprocessor transforming some c++ syntax into AngelScript code
// Preprocessor.h ----------------------------
#ifndef __INCLUDED_SCRIPTING_ANGELSCRIPT_PREPROCESSING_H
#define __INCLUDED_SCRIPTING_ANGELSCRIPT_PREPROCESSING_H
#include <string>
#include <vector>
class Preprocessor
{
public:
@quarnster
quarnster / test.cpp
Created September 9, 2012 18:48
Minimal libclang test code
// clang test.cpp -lclang -o ./test && ./test
// gcc test.cpp -lclang -o ./test && ./test
#include "clang-c/Index.h"
#include <stdio.h>
int main(int argc, char** argv)
{
CXIndex idx = clang_createIndex(1, 0);
const char *clangargs[] =
{
@quarnster
quarnster / conv.py
Created September 27, 2012 18:54
Convert WebEdit commands to Sublime Text 2 keybinding snippets
# Usage: python conv.py < input.txt > output.json
import re
import sys
for line in re.findall(r".*?=([^\"\n]+[^\n]+)", sys.stdin.read()):
count = 1
regex = re.compile(r"((\w+)=\"([^\"$\n]+)\")")
match = regex.search(line)
while match:
line = "%s%s=\\\"${%d:%s}\\\"%s" % (line[:match.start()], match.group(2), count, match.group(3), line[match.end():])
@quarnster
quarnster / script.lua
Created October 6, 2012 19:22
Wireshark lua script for capturing audio/mpeg content
-- tshark -i tap0 -Xlua_script:./script.lua -f "src port 80" -O HTTP > /dev/null
function lastfile()
local max = 0
for filename in io.popen("ls data/*.mp3"):lines() do
local curr = tonumber(string.sub(filename, filename:find("%d+")))
if curr > max then
max = curr
end
@quarnster
quarnster / debug.sh
Created October 15, 2012 14:56
Android debugging. Put debug.sh in your path somewhere for easy access
#!/bin/bash
startdir=`dirname $0`
if [ $# -lt 1 ]
then
echo "usage: $0 /path/to/your/library.so packagename.of.your.activity"
echo " or"
echo "usage: $0 /path/to/your/executable"
@quarnster
quarnster / cmake_options_script.py
Created October 24, 2012 05:40
SublimeClang options script taking the compilation commands from CMake. Based on @berenm's pull request https://github.com/quarnster/SublimeClang/pull/135
# Based on @berenm's pull request https://github.com/quarnster/SublimeClang/pull/135
# Create the database with cmake with for example: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
# or you could have set(CMAKE_EXPORT_COMPILE_COMMANDS ON) in your CMakeLists.txt
# Usage within SublimeClang:
# "sublimeclang_options_script": "python ${home}/code/cmake_options_script.py ${project_path:build}/compile_commands.json",
import re
import os
import os.path
@quarnster
quarnster / dns.py
Created November 1, 2012 18:04
A tiny python dns proxy script
# Based on code originally from http://code.activestate.com/recipes/491264-mini-fake-dns-server/
#
# DNS rfc: http://www.ietf.org/rfc/rfc1035.txt
# http://en.wikipedia.org/wiki/List_of_DNS_record_types
import socket
import re
import sys
import traceback
import struct
import Queue
@quarnster
quarnster / nn.hs
Created January 24, 2013 19:20
Neural Network in Haskell with some memory usage wierdness
-- Compile with ghc -O2 -msse4.2 --make nn -rtsopts
-- Run with ./nn False +RTS -s
-- .....
-- 812,842,896 bytes allocated in the heap
-- 592,620,616 bytes copied during GC
-- 63,771,584 bytes maximum residency (11 sample(s))
-- 1,063,968 bytes maximum slop
-- 180 MB total memory in use (0 MB lost due to fragmentation)
--
-- Tot time (elapsed) Avg pause Max pause
@quarnster
quarnster / fetch.js
Created June 1, 2013 18:44
Small javascript for fetching all files in a document.
var re = new RegExp("download|subtitle.*srt|class_resources|slides")
for (var i in document.links)
{
var link = document.links[i].href;
if (re.test(link)) {
window.open(link);
}
}