Skip to content

Instantly share code, notes, and snippets.

@candycode
candycode / auto-test.sh
Created December 10, 2012 13:47
Automated test runner script
TEST_DRIVER=$1
TEST_DIR=$2
PASSED=0
FAILED=0
if [ -z $TEST_DRIVER ] || [ -z $TEST_DIR ]; then
echo "Usage: $0 <test driver> <test directory>"
else
for f in $( ls $TEST_DIR/*.py ); do
TOTAL=$[TOTAL+1]
echo "__________________________________"
@candycode
candycode / git-version-cmake.txt
Created December 6, 2012 11:07
Add git repo version info as #define with CMake
#look for a tag...
exec_program(
"git"
${CMAKE_CURRENT_SOURCE_DIR}
ARGS "describe"
OUTPUT_VARIABLE GIT_TAG )
#...if not found get the SHA1 hash instead
if( ${GIT_TAG} MATCHES "fatal:.*" )
exec_program(
@candycode
candycode / CMakeLists-qt-python.txt
Created November 13, 2012 08:38
Qt + Python CMake config
cmake_minimum_required(VERSION 2.8)
project(qpy)
#Qt
find_package(Qt4 REQUIRED QtCore)
include(${QT_USE_FILE})
#Python
find_package(PythonLibs)
include_directories( ${PYTHON_INCLUDE_DIRS} ${QT_INCLUDES} )
@candycode
candycode / TestObject.h
Created November 13, 2012 08:34
Invoke QObject constructor at run-time
// use with qmetaobject-newinstance.cpp
#include <iostream>
#include <QObject>
#include <QString>
#include <QVariantMap>
#include <QVariantList>
#include <QList>
#include <QVector>
@candycode
candycode / websocketserver.py
Created October 22, 2012 15:17 — forked from jkp/websocketserver.py
A simple WebSockets server with no dependencies
import struct
import SocketServer
from base64 import b64encode
from hashlib import sha1
from mimetools import Message
from StringIO import StringIO
class WebSocketsHandler(SocketServer.StreamRequestHandler):
magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
@candycode
candycode / core.clj
Last active August 29, 2015 14:16 — forked from Misophistful/core.clj
(ns apples.core
(:require [play-clj.core :refer :all]
[play-clj.g2d :refer :all]
[play-clj.math :refer :all]))
(declare apples main-screen)
(def speed 14)
(defn- get-direction []
(cond
@candycode
candycode / chrome-disable-security-for-local-access
Created April 6, 2014 15:05
Disable web security to access local resources as needed
FROM STACK OVERFLOW
http://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome
$ open -a Google\ Chrome --args --disable-web-security
For Linux run:
$ google-chrome --disable-web-security
Also if you're trying to access local files for dev purposes like AJAX or JSON, you can use this flag too.
-–allow-file-access-from-files
@candycode
candycode / extract-video-frames
Created April 6, 2014 12:00
extract frames from video
# ffmpeg -i file.mp4 -y -ss 5 -an -sameq -f image2 -r 1/5 filename%03d.jpg
-y
Overwrite output files
-ss position
Seek to given time position in seconds. "hh:mm:ss[.xxx]" syntax is also supported
-an
Disable audio recording
@candycode
candycode / cef-qt-ubuntu.sh
Created March 10, 2014 16:22
Build chromium embedded framework app w/ qt on ubuntu 13.04
#!/bin/sh
#NOTE: need to set L to the proper libcef_dll top level dir: ../out/Release/obj.target
g++ -I../ -o qt qt.cpp cefw.cpp `pkg-config --cflags gtk+-2.0` \
`pkg-config --libs gdk-2.0` \
-L../out/Release/obj.target -L../Release -lcef_dll_wrapper -lcef `pkg-config --cflags QtCore QtGui --libs QtCore QtGui`
@candycode
candycode / SyncQueue.h
Created February 21, 2014 13:21
Synchronized C++11 queue implementation
//sync queue implementation
#pragma once
#include <condition_variable>
#include <mutex>
#include <deque>
//------------------------------------------------------------------------------
//synchronized queue (could be an inner class inside Executor):
// - acquire lock on insertion and notify after insertion
// - on extraction: acquire lock then if queue empty wait for notify, extract