Skip to content

Instantly share code, notes, and snippets.

@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"
@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 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;
@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 / bunch_mark.rb
Last active Dec 19, 2015
Quick "who's better" - Benchmark script
View bunch_mark.rb
require 'benchmark'
class Bunch
def self.mark(&block)
first = Bunch.realtime(&block)
vs = {:first => first}
class << vs
def vs(&block)
@knugie
knugie / meta_module3.rb
Last active Dec 21, 2015
metaprogramming with modules in ruby This will only work with ruby 2.0 http://ruby-doc.org/core-2.0/Module.html#method-i-prepend
View meta_module3.rb
module One
def a(*)
puts 'One...'
super
end
end
module Two
def a(*)
puts 'Two...'
@knugie
knugie / lookup.rb
Last active Dec 24, 2015
ruby lookup table using Hash
View lookup.rb
#Lookup Tables, http://en.wikipedia.org/wiki/Lookup_table
#Memoization, http://en.wikipedia.org/wiki/Memoization
require 'benchmark'
###########################################################
# Fibonacci number, http://en.wikipedia.org/wiki/Fibonacci_number
def fib(n)
n < 2 ? 1 : fib(n-2) + fib(n-1)
end
@knugie
knugie / rename_to_date.sh
Created Jun 28, 2013
Rename all file in the current directory according to their file creation date For jpegs the file date will be set according to its EXIF data e.g. "20130628_014218.txt" not renamed "test.TXT" => "20130628_002938.txt" file extensions will be lower case
View rename_to_date.sh
#!/usr/bin/env sh
# Rename all file in the current directory according to their file creation date
# For jpegs the file date will be set according to its EXIF data
# e.g.
# "20130628_014218.txt" not renamed
# "test.TXT" => "20130628_002938.txt"
# file extensions will be lower case
jhead -ft -dt -autorot -exonly -n%Y%m%d_%H%M%S *.[Jj][Pp][Gg]
@knugie
knugie / .zshrc
Last active Jan 3, 2016
# Use alt+arrow to move cursor by word# Mac OS X El Capitan # iTerm2 # zsh # ~/.zshrc
View .zshrc
# Use alt+arrow to move cursor by word
# https://gist.github.com/knugie/fc9964695951b4c13ed3
# Mac OS X El Capitan # iTerm2 # zsh
# ~/.zshrc
bindkey -e
bindkey '\e\e[C' forward-word
bindkey '\e\e[D' backward-word