Skip to content

Instantly share code, notes, and snippets.

View hvrauhal's full-sized avatar

Heikki Rauhala hvrauhal

View GitHub Profile
@hvrauhal
hvrauhal / Bulk File Transfer From HFS+ usb drive to Windows 10 ntfs drive.md
Last active October 26, 2021 07:13
Transferring 1.7TB of data from an HFS+ USB2 drive to Windows 10 NTFS

Bulk File Transfer From HFS+ usb drive to Windows 10 NTFS disk

Why not just copy via SMB?

First I tried to just copy the contents from an SMB share running on MacOS side. That was super slow, and considering also the impossibility of resuming, or knowing what actually got transferred, I did not think that would be the route to go.

Next I tried to naively rsync over an SMB mounted windows drive from the MacOS side, but the problem is that the local diff algorithm does not work over network, as all the data is transferred to the same process for comparison, and even skipping the rsync algorithm, the transfer speed was really low.

I have previously fought with ssh to get it to transfer files at full speed and decided to skip that battle this time.

@hvrauhal
hvrauhal / generate_samples.sh
Created April 15, 2020 10:09
Generate video sample files suitable for Android Emulator testing
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Audio generation
python3 - << EOF
import subprocess
@hvrauhal
hvrauhal / create_sounds.py
Last active May 19, 2020 06:57
Create OpenTX Taranis sound files with MacOS say command to replace the ones on the card
#!/usr/bin/env python3
import argparse
import csv
import subprocess
from pathlib import Path
def create_sounds(sdcard_path: Path, voice: str, lang: str):
path_to_system = sdcard_path / 'SOUNDS' / lang / 'SYSTEM'
with (next(path_to_system.glob('*-taranis.csv')).open(newline='')) as csvfile:
@hvrauhal
hvrauhal / Breakpoint-remixing.sol
Created May 23, 2018 08:53
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24-nightly.2018.5.16+commit.7f965c86.js&optimize=false&gist=
pragma solidity ^0.4.23;
contract BreakpointSample {
address public owner;
uint256 public blockNumberToUnlock;
constructor (address _owner, uint256 blocksToUnlock) public {
if (_owner == address(0)) {
owner = msg.sender;
} else {

How to identify my most expensive queries using pg_stat_statements

First enable the library for the server by adding the following line to postgresql.conf:

shared_preload_libraries = 'pg_stat_statements'

If you've installed postgresql with homebrew, the configuration file is at /usr/local/var/postgres/postgresql.conf

Then enable the extension for the databases that you're interested in with

#!/bin/zsh
# brew install ffmpeg
set -e
FILENAME=$1
echo "Recompressing $FILENAME"
VIDEO_BITRATE=512k
ffmpeg -i ${FILENAME} -codec:a copy -y -c:v libx264 -preset veryslow -b:v ${VIDEO_BITRATE} -pass 1 -f mp4 /dev/null && \
ffmpeg -i ${FILENAME} -codec:a copy -c:v libx264 -preset veryslow -b:v ${VIDEO_BITRATE} -pass 2 ${FILENAME}_compressed.mp4
drop table if exists gist_test;
create table gist_test (
bar text,
foo text,
constraint gist_test_bar_unique unique (bar),
constraint gist_test_foo_gist_unique exclude using gist (foo with =)
);
insert into gist_test (bar, foo) values ('bar', 'foo');
insert into gist_test (bar, foo) values ('baz', 'foo')
on conflict on constraint gist_test_bar_unique
@hvrauhal
hvrauhal / bb.js
Last active June 3, 2019 10:59 — forked from stephantabor/bb.js
Bluebird .mapSeries vs .map
var Promise = require('bluebird');
var funcs = Promise.resolve([100, 200, 300, 400].map((n) => makeWait(n)));
console.log('first with {concurrency: 1}');
funcs
.map(iterator, {concurrency: 1})
.then(function(r) { console.log('Resolved with', r) } )
.then(function() {
console.log('then with mapSeries');
@hvrauhal
hvrauhal / convert-to-vp9-ogg-webm-and-normalize-audio.sh
Last active April 17, 2016 17:13
This script uses ffmpeg to convert video to vpx9 and audio to vorbis, then sox to normalize audio, and finally ffmpeg to bundle the streams back together
#!/bin/zsh
# Install needed tools:
# brew install sox --with-libvorbis
# brew install ffmpeg --with-libvpx --with-libvorbis --with-opus --with-faac
set -e
FILENAME=$1
echo "Converting $FILENAME to webm + ogg with normalized audio"
ffmpeg -i ${FILENAME} -c:a libvorbis -vn ${FILENAME}_audio_orig.ogg
ffmpeg -i ${FILENAME} -c:v libvpx-vp9 -crf 50 -b:v 0 -vf scale=840:-1 -g 50 -an ${FILENAME}_video_orig.webm
@hvrauhal
hvrauhal / rollback-before-modifications.js
Created August 24, 2015 10:08
This demonstrates a problem when using async disposers with bluebird's using
var Promise = require('bluebird')
var using = Promise.using
var statefulResource = {
closed: false,
log: function (param) {
if (!statefulResource.closed) {
console.log('resource usage:', param)
} else {
console.log('resource no longer available for logging', param)