Skip to content

Instantly share code, notes, and snippets.

View keybase.md

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:

@kfei
kfei / imageDimension.js
Created Oct 6, 2015
Get image dimension
View imageDimension.js
// 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
Migrate USB OS to mdadm RAID array on Arch Linux
View gist:98179580527cf17c6507
# 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 Aug 29, 2015
Scrapy example for BusinessEnglishPod.com
View item.py
# -*- 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 Aug 29, 2015
profile comparison for cie94 and yiq
View using-cie94
(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
@kfei
kfei / gist:d3f3e36136c39cfab5e5
Created Jan 21, 2015
Adding new packages to customized CentOS 7
View gist:d3f3e36136c39cfab5e5
# Resolve all dependencies for packages that are going to be installed
for pkg in "virt-top cifs-utils redhat-lsb"; do repoquery --requires --resolve --recursive $pkg | grep -vE "i686" > dep-for-$pkg.log
# For a .rpm file, resolving dependencies can be `rpm -qpR mediawiki-1.4rc1-4.i586.rpm`
# Remove duplicates
awk '!x[$0]++' `cat dep-for-$pkg.log` > all-deps.log
# Extract package name from .deb file name
awk -F ":" '{print $1}' all-deps.log | sed -e 's/-[[:digit:]]\+$//g' > deps.log
@kfei
kfei / ffmpeg.sh
Last active Oct 22, 2019
Screen recording using a dockerized ffmpeg
View ffmpeg.sh
#!/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 $*
View gist:53a680d53bea1bab9f4c
func main() {
args := os.Args
arg := make([](*_Ctype_char), 0)
l := len(args)
for i, _ := range args {
char := C.CString(args[i])
// defer C.free(unsafe.Pointer(char))
strptr := (*_Ctype_char)(unsafe.Pointer(char))
arg = append(arg, strptr)
}
@kfei
kfei / gist:5dbb32f118f373fc1a47
Last active Apr 25, 2020
Convert GIF using ffmpeg and ImageMagick
View gist:5dbb32f118f373fc1a47
# 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
View gist:3e7f6de180ac84dd7fa1
RUN buildDeps='gcc libc6-dev make'; \
set -x \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/redis \
&& curl -sSL "$REDIS_DOWNLOAD_URL" -o redis.tar.gz \
&& echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - \
&& tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \
&& rm redis.tar.gz \
&& make -C /usr/src/redis \
You can’t perform that action at this time.