Skip to content

Instantly share code, notes, and snippets.

View wteuber's full-sized avatar

Wolfgang Teuber wteuber

View GitHub Profile
@wteuber
wteuber / fail.js
Created May 23, 2013 11:36
JS Brainfuck
(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]
/*"fail"*/
(![]+[])[ +[] ] /*("false")[0]*/
+
(![]+[])[ +!+[] ] /*("false")[1]*/
+
([![]]+[][[]])[ +!+[]+[+[]] ] /*("falseundefined")[10]*/
+
@wteuber
wteuber / standup_note.rb
Created May 23, 2013 11:50
standup note
################# CODE #################
def standup_note
'heute: Standup ' + ((Time.now.day % 2).zero? ? 'gegen den ' : 'im ') + 'Uhrzeigersinn'
end
################# PREP #################
class String
def should_include(part)
raise '...but it does not!' unless self.include?(part)
@wteuber
wteuber / locale_yaml_formatter.rb
Last active April 18, 2019 12:34
Sort your rails locale yamls alphabetically and adds an empty line when indent lowers 2 or more levelsPrints everything to stdout. Watch your yaml anchors and aliases (fix manually, if needed).usage: chmod +x ./locale_yaml_formatter.rb ./locale_yaml_formatter.rb <path/to/locale.yml>In a rails project, runfind . -type f -name *.yml | grep -v spec…
#!/usr/bin/env ruby
# Sort your rails locale yamls alphabetically and adds an empty line when indent lowers 2 or more levels
# Prints everything to stdout. Watch your yaml anchors and aliases (fix manually, if needed).
# usage:
# chmod +x ./locale_yaml_formatter.rb
# ./locale_yaml_formatter.rb <path/to/locale.yml>
#
# In a rails project, run
# find . -type f -name *.yml | grep -v spec | grep locales | _
@wteuber
wteuber / git_synch_fork.sh
Created August 9, 2013 10:22
synch your fork of a repo
git checkout master
git reset --hard origin/master
git remote -v
#should list origin (fork) and upstream (original repo)
#git remote add upstream https://github.com/original/repo.git
git fetch upstream
git merge upstream/master
git push origin master
#also see https://help.github.com/articles/syncing-a-fork
@wteuber
wteuber / fmod.js
Last active February 6, 2024 14:47
fmod for Javascript, will work with any ECMA-262 implementation.If you need a precision higher than 8, please use another implementaion of fmod.
/*
fmod for Javascript, will work with any ECMA-262 implementation.
If you need a precision higher than 8, please use another implementation of fmod.
1.05 % 0.05
=> 0.04999999999999999
Math.fmod(1.05, 0.05)
=> 0
@wteuber
wteuber / what.js
Created August 20, 2013 12:41
JS large numbers "WHAT?"
/*This will alert 'WHAT?':*/
if (100000000000000001 === 100000000000000000) { alert('WHAT?'); }
/*jslint indent: 2 */
/* toFixed converts the input to a number and returns it rounded to 2 decimal places */
/* For a deeper insight on javascript numbers, read http://ecma-international.org/ecma-262/5.1/#sec-8.5 */
function toFixed(val) {
'use strict';
var floatError = 1000000, /* floating point errors less than (1/floatError) == 0.000001 will be corrected */
decRound = 100, /* the result is rounded to integer multiples of (1/decRound) == 0.01 */
n = parseFloat(val), /* convert input to floating point number */
sign = n < 0 ? '-' : '', /* sign of the given input */
intFrac, /* integer and fractional parts of a decimal number */
/*jslint indent: 2 */
// http://toys.usvsth3m.com/javascript-under-pressure/
function doubleInteger(i) {
'use strict';
// i will be an integer. Double it and return it.
return i * 2;
}
@wteuber
wteuber / ruby_floating_point_errors.rb
Last active December 26, 2015 20:39
Ruby's floating point errors
# Ruby's floating point errors
# "Sometimes it's easier avoiding a problem than solving it."
0.2 > (1.to_r/5) # false
0.2.to_r == 0.2 # true
0.2.to_r > (1.to_r/5) # true
# There is a certain range of floating point calculation errors, which is ignored.
0.2.to_r # (3602879701896397/18014398509481984)
0.2.to_r - (1.to_r/5) # (1/90071992547409920) (it should be 0)
@wteuber
wteuber / gtk.css
Created November 6, 2013 09:46
gtk.css - change color of active terminal tab of gnome-terminal
/* ~/.config/gtk-3.0/gtk.css */
TerminalWindow .notebook tab {
background-color: #AAA;
}
TerminalWindow .notebook tab:active {
background-color: #FFF;
}