Skip to content

Instantly share code, notes, and snippets.

View sdumetz's full-sized avatar

Sebastien Dumetz sdumetz

View GitHub Profile
@sdumetz
sdumetz / recursive-rmdir.js
Created April 22, 2014 15:00
async recursive rmdir for node js
var fs = require('fs');
var rmdir = function(dir,callback){
var i=0;
var count = 0;
var clbk = function(err){
count++;
console.log(" %s vs %s",count,i);
if(count >= i){
fs.rmdirSync(dir);
callback(err)
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@sdumetz
sdumetz / vlc-thumb
Last active August 29, 2015 14:15
Make a thumbnail of a video using VLC and imagemagick. No real improvement over using ffmpeg except if you have VLC installed and not ffmpeg.
#!/bin/sh
# usage :
# @param source video
# @param destination
set -e
### USAGE HELPER ######
usage () {
echo "takes a thumbnail from a video"
echo ""
@sdumetz
sdumetz / Useful Bash
Last active August 29, 2015 14:15
check command existence, get script dir...
### CHECK IF COMMAND IS AVAILABLE ###
command -v foo >/dev/null 2>&1
if [ $? -eq 0 ]; then
#Command found
else
#command not found
fi
###GET SCRIPT DIRECTORY ####
DIR="$( cd "$( dirname "$0" )" && pwd )"
@sdumetz
sdumetz / UnityListener
Last active November 3, 2021 08:46
unity3D TcpListener example
public class UnityListener{
public UnityListener(){
tcpClientConnected = new ManualResetEvent(false);
server = new TcpListener(IPAddress.Parse("127.0.0.1"),8080);
server.Start();
// Set the event to nonsignaled state.
tcpClientConnected.Reset();
Debug.Log("Waiting for a connection...");
server.BeginAcceptTcpClient(
new AsyncCallback(DoAcceptTcpClientCallback), server);
@sdumetz
sdumetz / gist:61c1d61c00a4326feae1
Last active August 29, 2015 14:22
evdev events read and parse
var fs = require('fs');
var read = function(device){
, stream;
try {
stream = fs.createReadStream(device, {
flags: 'r',
encoding: null
})
.on('data', function(buf){
var i,j,chunk = 24;
@sdumetz
sdumetz / build.sh
Last active September 24, 2015 11:01
barebones script to build deb packages
#!/bin/sh
# basic deb package building
set -e
DIR="$( cd "$( dirname "$0" )" && pwd )"
NODE_ENV=production
VERSION=$(head -1 $DIR/debian/changelog|sed -r 's/.*\(([^\)]*)\).*/\1/')
NAME=$(head -1 $DIR/debian/changelog|cut -d " " -f 1)
TMP=$(mktemp -d)
@sdumetz
sdumetz / video RDF check script
Last active January 12, 2017 13:54
Try to compare rate distortion factor between h.264 and vp8 encoding.
#!/bin/sh
set -e
IN="$1"
TMP=$(mktemp -d)
mkdir "$TMP/src"
#create our sample videos
avconv -f image2 -i "$IN" "$TMP/src/frame-%04d.png"
#H.264 profiles
avconv -f image2 -i "$IN" -c:v h264 -c:a none -pix_fmt yuv420p -profile:v main -level 31 "$TMP/out.mp4"
avconv -f image2 -i "$IN" -c:v h264 -c:a none -pix_fmt yuv420p -profile:v high -level 41 "$TMP/out_h.mp4"
//Rough implementation of application/JSOn formData submission https://darobin.github.io/formic/specs/json/
function jsonFromForm(form){
const formdata = new FormData(form);
//use iterable property of form.keys() to send JSON
const data = {};
for(let key of formdata.keys()){
data[key] = formdata.get(key);
}
return JSON.stringify(data);
}
@sdumetz
sdumetz / Encoder.hpp
Created May 19, 2017 14:44
barebone C++ MPEG4/h264 video encoder using libavformat and libavcodec. Options choice is explained in https://sdumetz.github.io/2017/05/19/libav-encoding-for-ios.html
#include <stdio.h>
#include <iostream>
extern "C"{
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h> //for av_image_alloc only
#include <libavutil/opt.h>