Skip to content

Instantly share code, notes, and snippets.

@mharsch
mharsch / gist:1239436
Created September 24, 2011 15:11
randomly access memory within an allocated range
Random integer in range algorithm:
given that rand() produces a random number between 0 and RAND_MAX (defined in stdlib.h)
and we want a random integer (rand_index) between 0 and page_range where page_range = malloc_size / page_size
page_range = malloc_size / page_size;
if ( RAND_MAX > page_range ) {
rand_index = ( rand() % page_range ) * page_size;
} else {
@mharsch
mharsch / gist:1911743
Created February 25, 2012 23:57
Create a facebook test user using node.js
var qs = require('querystring');
var request = require('request');
var app_id = '<your_fb_app_id>';
var app_secret = '<your_fb_app_secret>';
var app_login_url = 'https://graph.facebook.com/oauth/access_token'
var app_login_qs = {
client_id: app_id,
client_secret: app_secret,
@mharsch
mharsch / gist:1964199
Created March 3, 2012 03:39
create a pair of facebook test users and make them friends
var qs = require('querystring');
var request = require('request');
var fbapp = {
id: '<your fb app id>',
secret: '<your fb app secret>'
};
var fb_perm = 'email,user_birthday,user_interests,user_location,friends_birthday,friends_interests,friends_location,publish_stream,offline_access,sms';
@mharsch
mharsch / gist:2918235
Created June 12, 2012 15:34
notes on porting v8plus to linux
--- notes from my initial pass trying to get wesolows/v8plus to work on linux ---
Download source for both SPL (Solaris Portability Layer) and ZFS from
zfsonlinux.org. Build both SPL and ZFS packages. Now you have the libnvpair
library and the necessary solaris header files to build v8plus.
Modify v8plus Makefile.v8plus.defs as follows
add '-I' include directives to CPPFLAGS for /tmp/zfs/lib/libspl/include and
/tmp/zfs/include (assuming you downloaded the zfs on linux repo to /tmp)
add -DHAVE_IOCTL_IN_UNISTD_H to CPPFLAGS
@mharsch
mharsch / gist:3057893
Created July 6, 2012 03:26
notes on getting gdev to build on Ubuntu 11.04
I describe here a ground-up set of steps to get shinpei0208/gdev to compile and load on
Ubuntu 11.04 with a GeForce GTX 550 Ti (NVC0) card.
1.) Install Ubuntu 11.04 Server. Run apt-get upgrade and apt-get dist-upgrade
(ending up running kernel 2.6.38-15-server)
2.) Download the mainline kernel source using the procedure described here
(stop after step 3): https://wiki.ubuntu.com/KernelTeam/GitKernelBuild
3.) Checkout the v3.3 version of the kernel source tree:
@mharsch
mharsch / gist:3800817
Created September 28, 2012 16:34
install libnvpair on Ubuntu
libnvpair is available as a nice independent bundle from the ZFS on Linux project.
To install libnvpair (and it's dependencies) on Ubuntu:
sudo add-apt-repository ppa:zfs-native/stable
sudo apt-get update
sudo apt-get install libnvpair1
@mharsch
mharsch / gist:4039775
Created November 8, 2012 16:10
display resolution mismatch on chromebook
Connecting a 2012 samsung chromebook XE303C12 ($249 ARM-based model) to a Dell E2209W 22"
widescreen LCD monitor (using a DVI to HDMI cable) produces inconsistent resolution
detection for the external monitor. The E2209W reports it's optimal resolution
(when connected to the chromebook) to be 1680x1050@60Hz, but often syncs at 1788x1050@60Hz.
On my system, this produces a black stripe on the right side of the screen. The state of
the external monitor (on/off, connected/disconnected) at boot-time determines whether
or not the resolution will successfully sync to the optimal setting. Through
trial-and-error, I've determined that the following sequence always lands on the optimal
monitor resolution:
@mharsch
mharsch / gist:4260240
Created December 11, 2012 16:53
build PAPI 5.0.1 with cuda component on Ubuntu 12.04 with CUDA 5
mharsch@linbrook:~/tmp$ uname -a
Linux linbrook 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
mharsch@linbrook:~/tmp$ cd papi-5.0.1/
mharsch@linbrook:~/tmp/papi-5.0.1$ cd src/components/cuda
mharsch@linbrook:~/tmp/papi-5.0.1/src/components/cuda$ echo $LD_LIBRARY_PATH
/usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/extras/CUPTI/lib64:/lib:
mharsch@linbrook:~/tmp/papi-5.0.1/src/components/cuda$ echo $PATH
/home/mharsch/local/bin:/usr/local/cuda-5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
mharsch@linbrook:~/tmp/papi-5.0.1/src/components/cuda$ ./configure --help|grep with-cu
--with-cuda_incdir=<path> Specify path to CUDA includes
@mharsch
mharsch / gist:5144208
Last active January 31, 2017 17:12
transcode video streams using node.js Streams and avconv (aka ffmpeg)

The avconv utility can be made to work in 'the Unix way' by specifying stdin and/or stdout instead of filenames for the input and output respectively. See: http://libav.org/avconv.html#pipe

Example:

cat input.ts | avconv -i pipe:0 -f mp4 -movflags frag_keyframe pipe:1 | cat > output.mp4

Using node's require('child_process').spawn(), we can pipe streams of video data through avconv's stdin and stdout and thus Stream All The Things.

var fs = require('fs');
@mharsch
mharsch / gist:5188206
Last active February 8, 2024 02:43
serve HLS (HTTP Live Streaming) content from node.js

HLS streaming from node

Provided that you already have a file or stream segmenter generating your .m3u8 playlist and .ts segment files (such as the ffmpeg 'hls' muxer), this little node server will serve up those files to an HLS compatible client (e.g. Safari). If you're using node for your streaming app already, this obviates the need to serve the HLS stream from a separate web server.

loosely based on https://gist.github.com/bnerd/2011232

// loosely based on https://gist.github.com/bnerd/2011232
// requires node.js >= v0.10.0
// assumes that HLS segmenter filename base is 'out'
// and that the HLS playlist and .ts files are in the current directory