Skip to content

Instantly share code, notes, and snippets.

@kfei
kfei / ffmpeg.sh
Last active April 12, 2024 21:21
Screen recording using a dockerized ffmpeg
#!/bin/bash
docker run -it --rm --privileged --net host \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $PWD:$HOME/workspace \
-v $HOME/.Xauthority:$HOME/.Xauthority \
-e HOME=$HOME \
-e DISPLAY=$DISPLAY \
--entrypoint /usr/sbin/ffmpeg \
kfei/ffmpeg $*
@kfei
kfei / fileio3.py
Created October 13, 2014 02:35
A Python3 ZMQ file transfer example
# File Transfer model #3
#
# In which the client requests each chunk individually, using
# command pipelining to give us a credit-based flow control.
import os
import sys
from threading import Thread
import zmq
@kfei
kfei / gist:5dbb32f118f373fc1a47
Last active April 25, 2020 03:25
Convert GIF using ffmpeg and ImageMagick
# Use ffmpeg to decode input video (GIF in this case)
ffmpeg -i input.gif decode/%d.png
# Use ImageMagick to crop, format: (W)x(H)+(W_SFHIT)+(H_SHIFT)
# Note the {from..to..skip} usage of Bash
convert decoded/{1..759..5}.png -crop 315x172+20+40 resized/%d.png
# An resize option
# convert decoded/{1..759..5}.png -crop 315x172+20+40 -resize 30% resized/%d.png

Keybase proof

I hereby claim:

  • I am kfei on github.
  • I am kfei (https://keybase.io/kfei) on keybase.
  • I have a public key ASBqABPMn4hnjXBn2PWO0agEIH4aBQoD7rqrykOtLG576go

To claim this, I am signing this object:

import java.io.IOException;
import java.io.InputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
public class Exec {
def get_interface_name
interfaces = {}
puts 'Valid network interfaces detected are:'
interfaces_with_mac = `ifconfig -a | grep -i hwaddr | awk '{ if( match($1, /^eth/) ) {print $1, $5} }'`.lines.map(&:chomp)
interfaces_with_mac.each_with_index do |x, index|
interfaces[index] = x.split[0]
puts " #{index}) #{x.split[0]} ( #{x.split[1]} )"
end
print 'Please choose an interface to configure: '
@kfei
kfei / imageDimension.js
Created October 6, 2015 02:19
Get image dimension
// With naturalWidth, naturalHeight
myImage.addEventListener('onload', function() {
console.log('My width is: ', this.naturalWidth);
console.log('My height is: ', this.naturalHeight);
});
// Without naturalWidth, naturalHeight
function realImgDimension(img) {
var i = new Image();
i.src = img.src;
@kfei
kfei / gist:98179580527cf17c6507
Created May 25, 2015 16:42
Migrate USB OS to mdadm RAID array on Arch Linux
# Create new array
mdadm --zero-superblock /dev/sd{a,b}
mdadm -C --level 1 /dev/md1 -n 2 /dev/sda2 /dev/sdb2
# Save to mdadm.conf since it will be used in initramfs for assembling arrays
mdadm --detail --scan >> /etc/mdadm.conf
# Make new file system and then migrate data
rsync -avxHAXS -P / /mnt/md1
@kfei
kfei / item.py
Last active August 29, 2015 14:20
Scrapy example for BusinessEnglishPod.com
# -*- coding: utf-8 -*-
# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html
import scrapy
@kfei
kfei / using-cie94
Last active August 29, 2015 14:13
profile comparison for cie94 and yiq
(pprof) top10
130ms of 130ms total ( 100%)
Showing top 10 nodes out of 11 (cum >= 80ms)
flat flat% sum% cum cum%
60ms 46.15% 46.15% 60ms 46.15% math.Sqrt
20ms 15.38% 61.54% 80ms 61.54% github.com/kfei/sshcam/img2xterm.cie94
20ms 15.38% 76.92% 20ms 15.38% runtime.usleep
10ms 7.69% 84.62% 10ms 7.69% retake
10ms 7.69% 92.31% 10ms 7.69% runtime.cas64
10ms 7.69% 100% 10ms 7.69% runtime.nanotime