Skip to content

Instantly share code, notes, and snippets.

@iamahuman
iamahuman / requirements
Created March 15, 2017 22:55
HCI support on Debian GNU/Linux
Basic support
bluez
bluez-tools
bluetooth
A2DP / Handset (on PulseAudio)
pulseaudio-module-bluetooth
OBEX
bluez-obexd
@iamahuman
iamahuman / stereo-test.pl
Created March 18, 2017 10:23
Stereo audio test (requires PulseAudio and pacat)
#!/usr/bin/perl
use Math::Trig;use IO::Handle;$s=44100;if(@ARGV[0]ne'o'){open($fh,"|pacat --rate=$s --format=s16le --channels=2");}else{$fh=*STDOUT;}$i=0;$d=2;$l=440;$r=880;$j=1;$a=8192;$la=0;$lb=0;$i=$s*$d-1;$n=0;while(1){if(++$i>=$s*$d){while(abs(int($la))>1 or abs(int($lb))>1){print $fh pack "vv",($la*=0.99),($lb*=0.99);}print "\x00"x4;sleep $n;$n=$d;$i=0;$j=!$j;printf STDERR " %5s (%6.1f Hz)\r", ($j?"Right":"Left"), ($j?$r:$l);STDERR->flush();}print $fh pack "vv",($la=$j?0:(sin($i*2*pi*$l/$s)*$a)),($lb=$j?(sin($i*2*pi*$r/$s)*$a):0);}
@iamahuman
iamahuman / boincscr-wrapper.sh
Created March 22, 2017 14:58
Workaroud for Rosetta@home's screensaver window attachment operation absence bug
#!/bin/sh
set -e
pid=
do_term() {
trap - INT TERM EXIT CHLD
echo "Do exit $pid"
if [ "$pid" ]
then
kill "$pid" 2> /dev/null || :
fi
@iamahuman
iamahuman / 50_issudfut
Created April 3, 2017 07:37
GRUB2 menu entry for Intel SSD Firmware Update utility
#!/bin/sh
set -e
. "$pkgdatadir/grub-mkconfig_lib"
issudfut_dir="/boot/issudfut"
issudfut_initrd="$issudfut_dir/initrd"
issudfut_vmlinuz="$issudfut_dir/vmlinuz"
if [ -f "$issudfut_initrd" -a -f "$issudfut_vmlinuz" ]
then
@iamahuman
iamahuman / extracted.go
Last active May 1, 2017 15:36
Golang runtime types extraction tests (reflect)
// package ""
// address 0x5bef60
type ObjectIdentifier []int
// address 0x5b6500
type RawContent []uint8
// address 0x5eaaa0
type nat []big.Word
// address 0x5ac800
type bool bool
// address 0x5acbc0
def rand(seed):
new_seed = (0x343fd * seed + 0x269ec3) & ((1 << 32) - 1)
randval = (new_seed >> 16) & 0x7fff
return randval, new_seed
# $Id: avrdude.conf.in 1371 2016-02-15 20:15:07Z joerg_wunsch $ -*- text -*-
#
# AVRDUDE Configuration File
#
# This file contains configuration data used by AVRDUDE which describes
# the programming hardware pinouts and also provides part definitions.
# AVRDUDE's "-C" command line option specifies the location of the
# configuration file. The "-c" option names the programmer configuration
# which must match one of the entry's "id" parameter. The "-p" option
# identifies which part AVRDUDE is going to be programming and must match
<?php
ini_set("display_errors", 0);
$ver_outer = explode('-', PHP_VERSION);
$ver_info = explode('.', $ver_outer[0]);
$ver_major = intval($ver_info[0]);
$ver_minor = intval($ver_info[1]);
$ver_release = intval($ver_info[2]);
if ($ver_major < 7 || ($ver_major == 7 &&
($ver_minor < 0 || ($ver_minor == 0 &&
@iamahuman
iamahuman / C99.js
Created May 1, 2017 15:27
naive C99 parser
function abstract_declarator(t,r){var w,a,$0,$1;a=C(r);if(a.pointer<t.length&&($0=this.pointer(t,a))){if(a.pointer<t.length)$1=this.direct_abstract_declarator(t,a);r.pointer=a.pointer;return{name:N,children:[$0,$1]};}a=C(r);$0=undefined;if(a.pointer<t.length&&($1=this.direct_abstract_declarator(t,a))){r.pointer=a.pointer;return{name:N,children:[$0,$1]};}return null;}function additive_expr(t,r){var w,a,$0,$1;a=C(r);if(a.pointer<t.length&&($0=this.multiplicative_expr(t,a))){for($1=[];a.pointer<t.length&&(w=this.additive_expr_i(t,a));$1[$1.length]=w);r.pointer=a.pointer;return{name:N,children:[$0,$1]};}return null;}function additive_expr_i(t,r){var w,a,$0,$1;a=C(r);if(a.pointer<t.length&&($0=this.TERMINAL(t,a,"+"))){if(a.pointer<t.length&&($1=this.multiplicative_expr(t,a))){r.pointer=a.pointer;return{name:N,children:[$0,$1]};}}a=C(r);if(a.pointer<t.length&&($0=this.TERMINAL(t,a,"-"))){if(a.pointer<t.length&&($1=this.multiplicative_expr(t,a))){r.pointer=a.pointer;return{name:N,children:[$0,$1]};}}return null;}fun
@iamahuman
iamahuman / dep.js
Created May 6, 2017 23:31
Simple async.js-like dependent task processing
function process_reqs (reqs) {
var dependents = {}; // name -> [dependents]
var completed = {};
var pending_cnts = {};
var hasOwn = Object.prototype.hasOwnProperty;
var leaf_tasks = [];
for (var key in reqs) {
if (!hasOwn.call(reqs, key)) continue;