Skip to content

Instantly share code, notes, and snippets.

@candycode
candycode / image-arraybuffer.js
Created March 7, 2014 15:24
Create a jpg image from ArrayBuffer data
// Simulate a call to Dropbox or other service that can
// return an image as an ArrayBuffer.
var xhr = new XMLHttpRequest();
// Use JSFiddle logo as a sample image to avoid complicating
// this example with cross-domain issues.
xhr.open( "GET", "http://fiddle.jshell.net/img/logo.png", true );
// Ask for the result as an ArrayBuffer.
xhr.responseType = "arraybuffer";
@candycode
candycode / mathjax-syntaxhughlighter.html
Last active November 1, 2022 21:26
MathJax + SyntaxHighlighter header
<!-- Syntax Highlighter Additions START -->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script>
@candycode
candycode / libwebsocket-server.c
Last active November 1, 2022 21:26
libwebsocket server
#include <stdio.h>
#include <stdlib.h>
#include <libwebsockets.h>
#include <string.h>
static int callback_http(struct libwebsocket_context * this,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len)
@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 / ld-preload-intercept-method.cpp
Created May 23, 2016 21:12 — forked from mooware/ld-preload-intercept-method.cpp
Intercept C++ methods with LD_PRELOAD
// this file is an example of how to intercept a C++ method by using the
// LD_PRELOAD environment variable of the GNU dynamic linker.
//
// it works like this:
//
// 1) define a method that will have the same symbol as the intercepted
// method when compiled. For example, the method Foo::getValue()
// defined here has the mangled symbol "_ZNK3Foo8getValueEv".
// tools like nm, objdump or readelf can display the symbols of
// binaries.
@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 / flv2mp4.sh
Created March 22, 2016 10:12
Convert multiple files with ffmpeg
for f in ../flv/*.flv; do echo "Converting $f"; g=`basename $f .flv`; ffmpeg -i ../flv/$f -c:v libx264 -crf 19 -strict experimental $g.mp4 || echo FAILED; done
@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
@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 / 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