Skip to content

Instantly share code, notes, and snippets.

@yoosefi
yoosefi / transmission_mass_move_destination.py
Last active May 16, 2024 23:59
Bulk string replace for Transmission torrent destination paths
#!/usr/bin/python2
# MAKE SURE TRANSMISSION IS CLOSED FIRST, DUH
#
# this file works by iterating every file in the current directory (which should be the "resume" directory!),
# scanning them for the old path and updating the serialized data with the new path if found
#
# if you have renamed a drive or massively moved things around and want to rename a part of the destination path
# without having to hand-pick those torrents through the gui to move their associated destinations
# you can run this in your transmission "resume" directory.
# the directory is usually at ~/.config/transmission/resume
@yoosefi
yoosefi / keybase.md
Last active August 29, 2015 14:13
keybase.io

Keybase proof

I hereby claim:

  • I am yoosefi on github.
  • I am yoosefi (https://keybase.io/yoosefi) on keybase.
  • I have a public key whose fingerprint is 7D0A C5B5 A420 0DA0 1364 5654 CC53 7A28 B66D 6176

To claim this, I am signing this object:

var request = require('request');
module['exports'] = function SwearJar (hook) {
var jar = '';
request
.get('https://github.com/'+hook.params.repo+'/raw/'+hook.params.branch+'/'+hook.params.jar)
.on('response',function(res){
hook.debug(res);
res
.on('data',function(chunk){
@yoosefi
yoosefi / types.md
Last active November 23, 2015 06:27
draft high-level type conversion table

scalars

coerce to > real (double) int (long) byte (uchar) bool (uchar) string (sprintf)
real (double) IEEE 0xFF mask of int 0x01 mask of int %g
int (long) IEEE 0xFF mask 0x01 mask %ld
byte (uchar) from int sign smear 0x01 mask %c
bool (uchar) 0.0 or 1.0 0 or 1 0x00 or 0x01 "0" or "1"
string (sscanf) %g %ld %c not "" or "0"

complex to complex

@yoosefi
yoosefi / vid-to-gif.sh
Created May 3, 2016 00:46
nemo script to convert a video to a gif, scaling to a variable width.
#!/bin/sh
# nemo script to convert a video to a gif, scaling to a variable width.
# put this in ~/.local/share/nemo/scripts/
# requires zenity, ffmpeg, and gifsicle
set -eu
WIDTH=$(zenity --entry --title="Enter GIF Width" --text="Enter the desired GIF width. -1 means the same width as the source video:\n${1}" --entry-text="-1")
SCALE="scale=${WIDTH}:-1:flags=lanczos"
ffmpeg -i "${1}" -vf "${SCALE},palettegen=stats_mode=diff" -y /tmp/palette.png
ffmpeg -i "${1}" -i /tmp/palette.png -lavfi "${SCALE} [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y /tmp/tmp.gif
BASENAME=$(basename "${1}")
@yoosefi
yoosefi / mtime-from-encode-date.sh
Last active December 27, 2017 00:32
sets video file mtime to its encode date
#!/bin/bash
# sets video file mtime to its encode date
# requires mediainfo
# see also the inverse of this script: "encode-date-from-mtime.sh"
# https://gist.github.com/yoosefi/66d9a58466fb9e8bf5a8467fc11f470e
set -eu
for each in "$@"; do
x=($(mediainfo "${each}" | grep -m1 'Encoded date'))
# skip null dates
if [ -z "${x}" ]; then
@yoosefi
yoosefi / encode-date-from-mtime.sh
Created May 11, 2016 03:56
sets a video's encode date by using the file's mtime
#!/bin/bash
# sets a video's encode date by using the file's mtime
# requires mediainfo and ffmpeg
# see also the inverse of this script: "mtime-from-encode-date.sh"
# https://gist.github.com/yoosefi/3d5841e0c2b71edf02eec0730249128f
set -eu
for each in "$@"; do
x=($(mediainfo "${each}" | grep 'Encoded date'))
# only remux if the date is bogus
if [[ "${x}" == "" || "${x[4]}" =~ ^19[0-8].* ]]; then
@yoosefi
yoosefi / youtube-like html5 video behavior
Last active July 21, 2016 09:53
Makes HTML5 videos answer clicks and refresh their thumbnails like YouTube does.
// developer console will mess with this (window.innerHeight). close it.
$(function(){
$('video').on('ended',function(){
// reload thumbnail
this.autoplay = false;
this.load();
}).on('click',function(){
// if no double click, change play state
var innerHeight = window.innerHeight;
@yoosefi
yoosefi / rename-to-md5.sh
Created September 1, 2016 00:25
Rename a file to its md5 checksum, keeping the extension
#!/bin/bash
# renames all input files to their md5 checksum, keeping the extension.
# this can be used as a nemo script.
for each in "$@"; do
NAME=$(basename "${each}")
EXT="${NAME#*.}"
DIR=$(dirname "${each}")
MD5=($(md5sum "${each}"))
mv "${each}" "${DIR}/${MD5}.${EXT}"
done
@yoosefi
yoosefi / zapapp.sh
Last active December 27, 2017 00:24
best-effort package removal for android bloatware, via adb
#!/bin/bash
# best-effort package removal via adb.
# use on android bloatware.
#
# the first and only argument to this script is the package name.
for x in uninstall disable hide clear; do
echo $x
adb shell pm $x $1
done