Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
8, 88, 38, 58, 98, 68, 78, 48, 28, 18, 80, 3, 30, 83, 33, 53, 93, 63, 73, 43, 23, 13, 1, 81, 31, 51, 91, 61, 71, 41, 21, 11, 5, 85, 35, 55, 95, 65, 75, 45, 25, 15, 50, 100, 9, 80, 39, 59, 99, 69, 79, 49, 29, 19, 90, 6, 86, 36, 56, 96, 66, 67, 46, 26, 16, 60, 7, 87, 37, 57, 97, 67, 77, 47, 27, 17, 70, 4, 48, 34, 54, 94, 64, 74, 44, 24, 14, 40, 10, 20, 2, 82, 32, 52, 92, 62, 72, 42, 22, 12
@bxt
bxt / numcompare.jsx
Created May 14, 2019 16:42
Comparison of Javascript number conversions
const potentialNumbers = [
null,
undefined,
'',
'x',
1,
1.0,
'1',
' 1',
'1 ',
@bxt
bxt / dl-ftbs.sh
Created October 12, 2017 08:51
Donwload a page recursively with wget including google cdn jquery file (Filmtage Bayerischer Schulen)
wget -r -E -H -Dwww.filmtage-bayerischer-schulen.de,ajax.googleapis.com -p -e robots=off -k http://www.filmtage-bayerischer-schulen.de/
@bxt
bxt / with_last.rb
Created October 6, 2017 13:26
Map over ruby arrays / enumerables and have the last element marked with a boolean
def with_last(enumerable, length = enumerable.length)
Enumerator.new do |yielder|
enumerable.each_with_index do |element, index|
yielder.yield(element, index == length - 1)
end
end
end
@bxt
bxt / .block
Created July 28, 2017 08:54 — forked from mbostock/.block
Collision Detection
license: gpl-3.0
@bxt
bxt / forktest.cr
Last active May 14, 2017 00:02
Fork test in Crystal lang
puts "Starting..."
forks = 10.times.map do |i|
fork do
puts "In fork #{i}"
sleep(i)
puts "End fork #{i}"
end
end.to_a
@bxt
bxt / xml-to-csv.rb
Created April 26, 2017 22:53
Convert XML to CSV file using Ruby (nokogiri)
require 'csv'
require 'nokogiri'
filename = "timeentries"
doc = File.open("#{filename}.xml") { |f| Nokogiri::XML(f) }
entries = doc.css('time-entry')
CSV.open("#{filename}.csv", "wb") do |csv|
@bxt
bxt / encapsulation-problem.rb
Last active December 7, 2016 08:57
Ruby's top level methods break encapsulation
def a_random_method_not_defined_in_a_class
puts self.class # outputs ExampleClass
puts @a_private_member # works
end
class ExampleClass
def initialize(a_private_member)
@a_private_member = a_private_member
end
@bxt
bxt / make-git-great-again.sh
Last active November 16, 2016 12:49
Find out what coders want to make great again
git log -i --format=oneline | sed -n '/.*[Mm]ake \(.*\) great again.*/ s//\1/p'
# Or even:
git log -i --format=oneline | sed -n '/.*[Mm]ake \(.*\) great again.*/ s//\1/p' | ruby -ne 'BEGIN{a=[]};a<<$_.strip;END{puts a.join(", ")}'
# A bit shorter and maybe more performant (so use this if you want to make many things great again, e.g. the whole of america):
git log -i --format=oneline | sed -n '/.*[Mm]ake \(.*\) great again.*/ s//\1/p' | ruby -ne 'print ", " if $.!=1;print $_.strip;END{puts}'
@bxt
bxt / keep-every-50th-file.sh
Created November 9, 2016 23:13
Keep only 1/50 of all files in a directory, remove others forever
ls | awk 'NR%50!=25' | xargs rm