Skip to content

Instantly share code, notes, and snippets.

View sdumetz's full-sized avatar

Sebastien Dumetz sdumetz

View GitHub Profile
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
WAITFORIT_cmdname=${0##*/}
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
<div data-id="{gdoc_id}" class="gdoc-embed-wrapper" style="position:relative;width:100%;">
<div style="padding-top: 141%"></div>
<script>
const parent = document.currentScript.parentElement;
const id = parent.dataset.id;
const t = "https://docs.google.com/document/d/"+id+"/export?format=pdf";
const loader = document.createElement("DIV");
loader.innerHTML = "Loading document...
Object.assign(loader.style, {
@sdumetz
sdumetz / puppeteer_hooks.js
Last active August 21, 2024 13:55
Use puppeteer with mocha --parallel while keeping just one browser instance
'use strict';
// Use puppeteer with mocha --parallel while keeping just one browser instance
// run with `mocha --require puppeteer_hooks.js`
// It uses puppetter's connect method to wire test suites to the browser
// See : https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerconnectoptions
//Access the browser in tests using `this.browser`
const fs = require('fs').promises;
const path = require('path');
const os = require('os');
@sdumetz
sdumetz / Firefox upstream installer
Last active June 10, 2020 14:00
Install firefox official stable release on debian stretch and consorts
#!/bin/sh
#Install firefox official stable release on debian stretch and consorts
set -e
TMP="$(mktemp -d)"
install_base="/usr/local"
echo "downloading latest firefox release..."
wget -O "$TMP/FirefoxSetup.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64&lang=fr"
echo "removing old firefox binaries"
test -d "$install_base/lib/firefox" && rm -rf "$install_base/lib/firefox"
echo "extracting..."
@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>
//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 / 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"
@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 / 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 / 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);