Skip to content

Instantly share code, notes, and snippets.

@knugie
knugie / use multiple github accounts
Created February 4, 2014 23:02
use multiple github accounts
# switching identities in order to use multiple github accounts on one computer, you have to:
# add to ~/.ssh/config according to current github user:
Host github.com
IdentityFile ~/.ssh/<rsa_id_for_current_user>
# set git user globally or locally according to current github user:
git config --local user.name "My Name"
@knugie
knugie / pdftk_snippets.sh
Last active May 25, 2022 19:42
usefull pdftk commands
# merge all pdf files from a directory to a single pdf file
pdftk *.pdf cat output out.pdf
# reverse page order of a pdf file
PDFTK_PAGES=$(pdftk in.pdf dump_data | grep NumberOfPages | sed "s/^.*: //")
pdftk in.pdf cat $PDFTK_PAGES-1 output out.pdf
# Strip metadata in pdf
PDFTK_FILE=in.pdf
pdftk $PDFTK_FILE dump_data | sed -e 's/\(InfoValue:\)\s.*/\1\ /g' | pdftk $PDFTK_FILE update_info - output out.pdf
@knugie
knugie / rgb2hsl.rb
Last active May 25, 2022 19:41
Convert RGB to HSL color model
def rgb2hsl(r,g,b)
r´ = r.to_f / 255
g´ = g.to_f / 255
b´ = b.to_f / 255
c_max = [r´, g´, b´].max
c_min = [r´, g´, b´].min
Δ = c_max - c_min
h = Δ.zero? ? 0 : (60 * case c_max
when r´ then ((g´ - b´) / Δ) % 6
when g´ then ((b´ - r´) / Δ) + 2
@knugie
knugie / cancelAllRequestAnimFrame.js
Created October 10, 2014 03:39
cancel all request animation frames
window.cancelRequestAnimFrame = ( function() {
return window.cancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout
} )();
for (var i = 1; i < 99999; i++) {
@knugie
knugie / install_makemkv.sh
Last active November 23, 2016 06:17
Ubuntu - Install MakeMKV 1.9.0
sudo apt-get install build-essential pkg-config libc6-dev libssl-dev libexpat1-dev libavcodec-dev libgl1-mesa-dev libqt4-dev
wget http://www.makemkv.com/download/makemkv-oss-1.9.0.tar.gz
wget http://www.makemkv.com/download/makemkv-bin-1.9.0.tar.gz
tar -xvf makemkv-oss-1.9.0.tar.gz
tar -xvf makemkv-bin-1.9.0.tar.gz
cd makemkv-oss-1.9.0/
./configure
make
sudo make install
@knugie
knugie / sort_quiz_question.rb
Created January 10, 2015 17:11
ruby sort quiz question
ary = [['a', :hello], ['b', :foo], ['b', :bar], ['b', :baz], ['a', :world]]
# QUIZ:
# How do you sort "ary" so equal objects stay in the same relative order to each other?
# "ary" should be sorted by the first element of each entry.
# Try now: http://tryruby.org/
expected = [['a', :hello], ['a', :world], ['b', :foo], ['b', :bar], ['b', :baz]]
# HINT:
@knugie
knugie / GIF-Screencast-OSX.md
Last active May 25, 2022 19:56 — forked from dergachev/GIF-Screencast-OSX.md
Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

/*jslint browser: true, indent: 2 */
(function () {
'use strict';
var rgb, style, idx = 0, store = {}, tiles = document.getElementById('box').childNodes;
for (idx; idx < tiles.length; idx += 1) {
rgb = tiles[idx].style.backgroundColor.split("(")[1].split(")")[0].split(",");
store[Math.sqrt(Math.pow(rgb[0], 2), Math.pow(rgb[2], 2), Math.pow(rgb[2], 2))] = tiles[idx];
}
style = Object.keys(store).map(function (key) { return [key, store[key]]; }).
sort(function (a, b) { return parseInt(a[0], 10) < parseInt(b[0], 10) ? 1 : -1; })[0][1].style;
@knugie
knugie / plain_binary_dump_and_restore.sh
Last active May 25, 2022 19:55
Dump and Restore binary files in hex format
xxd -p org.bin | tr -d '\n' > tmp
xxd -p -r tmp > cpy.bin
@knugie
knugie / mts_to_mp4.sh
Last active October 2, 2017 18:20
Convert (Sony) MTS files to MP4
ffmpeg -i in.mts -c:v mpeg4 -qscale:v 5 -acodec libmp3lame -b:a 192k out.mp4