Skip to content

Instantly share code, notes, and snippets.

@candycode
candycode / osgviewport_uniform.diff
Created May 18, 2012 08:12
Add osg_Viewport uniform to GLSL
Index: src/osgUtil/SceneView.cpp
===================================================================
--- src/osgUtil/SceneView.cpp (revision 13031)
+++ src/osgUtil/SceneView.cpp (working copy)
@@ -424,6 +424,11 @@
osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_ViewMatrixInverse",osg::Uniform::FLOAT_MAT4);
uniform->set(osg::Matrix::inverse(getViewMatrix()));
}
+ if( _activeUniforms && getCamera() && getCamera()->getViewport() ) {
+ osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_Viewport",osg::Uniform::FLOAT_VEC2);
@candycode
candycode / pyopencv-grab-frame.py
Created September 16, 2012 15:05
Python - OpenCV: Grab frame from webcam
#if opencv was installed through home-brew on mac
#sys.path.append('/usr/local/lib/python2.7/site-packages')
import cv2
#open window "Window"
cam = cv2.VideoCapture(0)
while True:
img = cam.read()[1]
cv2.imshow("Window",img)
@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 / 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 / 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 / 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 / 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 / gl-emscripten.sh
Created May 6, 2013 12:48
OpenGL(ES) with emscripten
emcc ../../Common/*.c MultiTexture.c -o mm.html -I ../../Common -lGLESv2 -lEGL -lm -lX11 --preload-file basemap.tga --preload-file lightmap.tga
@candycode
candycode / yt2mp3.sh
Last active December 19, 2015 04:49
Download youtube audio from ubuntu: adds artist and title as metadata and copies everything into /Music/<artist> folder. Supports both flv and mp4 formats.
#!/bin/bash
#Original script:
#http://www.linuxjournal.com/content/grabbing-your-music-youtube-do-it-your-way
#modified to work with avconv
#Ubuntu >= 13.04: requires youtube-dl and the following packages:
#sudo apt-get install python-pip
#pip install youtube-dl
#sudo apt-get install libavcodec-extra-53 libav-tools
address=$1
regex='v=(.*)'
@candycode
candycode / dload-audio.sh
Last active December 19, 2015 07:09
Download and extract audio track from online video sites
youtube-dl -x -o "$(youtube-dl --get-filename -o "%(title)s.%(ext)s" $VIDEO_URL)" $VIDEO_URL