Skip to content

Instantly share code, notes, and snippets.

Wolfgang Teuber knugie

  • Leipzig
Block or report user

Report or block knugie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@knugie
knugie / use multiple github accounts
Created Feb 4, 2014
use multiple github accounts
View 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"
View pdftk_snippets.sh
# 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
View rgb2hsl.rb
def rgb2hsl(r,g,b)
= r.to_f / 255
= g.to_f / 255
= 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
whenthen ((g´ - b´) / Δ) % 6
whenthen ((b´ - r´) / Δ) + 2
@knugie
knugie / sort_quiz_question.rb
Created Jan 10, 2015
ruby sort quiz question
View sort_quiz_question.rb
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:
View GIF-Screencast-OSX.md

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:

View kuku_kube_helper.js
/*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;
View plain_binary_dump_and_restore.sh
xxd -p org.bin | tr -d '\n' > tmp
xxd -p -r tmp > cpy.bin
@knugie
knugie / showoff2png.js
Created Jun 25, 2012
Render Showoff presentation to png or pdf
View showoff2png.js
/* Render Showoff presentation to png or pdf.
For PNG output:
* Install
- phantomjs
* Run
$> showoff serve &
$> phantomjs ./path/to/showoff2png.js
This will create one png image file per slide.
* For PDF output:
@knugie
knugie / git_info.rb
Created Aug 17, 2012
print git statistics of users' numbers commits and added/deleted lines of code
View git_info.rb
#!/usr/bin/env ruby
# git_reports.rb
# print git statistics of users' commits and added/deleted lines of code
# simply run "ruby git_reports.rb" in a git repository
puts "git log --numstat --no-merges"
# retrieve data
log = %x"git log --numstat --no-merges"
@knugie
knugie / integer_underscore.rb
Last active Oct 13, 2015
Ruby Integer#underscore
View integer_underscore.rb
# <#Integer>.underscore(n) returns a string, seperating n digits by
# an underscore. n is 3 by default. This is supposed to make
# working with large numbers easier.
# example:
# 1000000000000000.underscore #=> "1_000_000_000_000_000"
# 100_00000_00_0000_00.underscore #=> "1_000_000_000_000_000"
# 987654321.underscore(6) #=> "987_654321"
class Integer
def underscore(s=3)
self.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1_")
You can’t perform that action at this time.