Skip to content

Instantly share code, notes, and snippets.

Bernhard Häussner bxt

Block or report user

Report or block bxt

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
@bxt
bxt / numcompare.jsx
Created May 14, 2019
Comparison of Javascript number conversions
View numcompare.jsx
const potentialNumbers = [
null,
undefined,
'',
'x',
1,
1.0,
'1',
' 1',
'1 ',
@bxt
bxt / dl-ftbs.sh
Created Oct 12, 2017
Donwload a page recursively with wget including google cdn jquery file (Filmtage Bayerischer Schulen)
View dl-ftbs.sh
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 Oct 6, 2017
Map over ruby arrays / enumerables and have the last element marked with a boolean
View with_last.rb
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 Jul 28, 2017 — forked from mbostock/.block
Collision Detection
View .block
license: gpl-3.0
@bxt
bxt / forktest.cr
Last active May 14, 2017
Fork test in Crystal lang
View forktest.cr
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 Apr 26, 2017
Convert XML to CSV file using Ruby (nokogiri)
View xml-to-csv.rb
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 Dec 7, 2016
Ruby's top level methods break encapsulation
View encapsulation-problem.rb
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 Nov 16, 2016
Find out what coders want to make great again
View make-git-great-again.sh
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 Nov 9, 2016
Keep only 1/50 of all files in a directory, remove others forever
View keep-every-50th-file.sh
ls | awk 'NR%50!=25' | xargs rm
@bxt
bxt / gitlab-openmr.sh
Last active Aug 1, 2017
Open the merge request for a merged commit in GitLab
View gitlab-openmr.sh
#!/bin/bash
set -e
MAIN=${2:-development}
OPEN=open
MRS=$(git remote show -n origin | sed -n '/^ Fetch URL: git@\(.*\):\(.*\)\.git$/ s//https:\/\/\1\/\2\/merge_requests\//p')
if [ -z "$1" ]
You can’t perform that action at this time.