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 / 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"
View bit_count_benchmark.rb
#!/usr/bin/env ruby
# coding: utf-8
require 'benchmark'
@count = 2_000_000
@lenght = 49
@pre_compute_16 = Array.new((2**16)) { |f| f.to_s(2).count('1') }
Strategy = Struct.new(:name, :method, :before)
@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_")
View print_all_files.sh
# Print each file in the current directory, including subdirectories with
# the full relative filename and its content, separated by 2 empty lines
# e.g.:
# ##### ./jasmine-coverage-javascript-coffeescript/Rakefile #####
# env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
# if env =~ /^(development|test)$/
# import 'lib/tasks/jasmine_coverage.rake'
# end
#
#
@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 / 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 / meta_module3.rb
Last active Dec 21, 2015 — forked from wteuber/meta_module2.rb
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 / reduce_pdf.sh
Created Oct 24, 2013
reduce pdf size
View reduce_pdf.sh
#reduce PDF size
#-dPDFSETTINGS
# /screen
# /ebook
# /printer
# /prepress
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -sOutputFile=out.pdf in.pdf
You can’t perform that action at this time.