Skip to content

Instantly share code, notes, and snippets.

View lsauer's full-sized avatar
🎯
Focusing

Lorenz Lo Sauer lsauer

🎯
Focusing
View GitHub Profile
@lsauer
lsauer / austria-citylist-letter-abbreviation.json
Last active August 29, 2015 13:55
JSON: Holidays in Austria's provinces - Austrian provinces ( Österreichische Feiertage )
{
"B": "Burgenland",
"K": "Kärnten",
"N": "Niederösterreich",
"O": "Oberöstereich",
"S": "Salzburg",
"St": "Steiermark",
"T": "Tirol",
"V": "Vorarlberg",
"W": "Wien"
@lsauer
lsauer / custom-scoped-setInterval-JavaScript.js
Created August 25, 2014 12:19
custom-scoped-setInterval-JavaScript.js: intervalCall binds a function to a declared scope and invokes it after 'tm' milliseconds
//lsauer.com, 2012 lo sauer
//description: intervalCall binds a function to a declared scope and invokes it after 'tm' milliseconds
//@param scope: scope in which the function should be invoked
//@param fn: the function to be invoked
//@param tm: timeout in milliseconds
//[@param fntimes]: Optional. A function to control the number of invocations of 'fn', i.e. to declare events / triggers based on the invocation-count
// fntimes is passed an integer Number-counter, starting at 1;
function intervalCall(scope, fn, tm, fntimes)
{
@lsauer
lsauer / a-invoke-a-bound-function-a-fixed-number-of-times-intervalCallNtimes.js
Created August 26, 2014 12:09
Custom scoped setInterval and repeat for n-times: intervalCallNtimes binds a function to a declared scope and invokes it after 'tm' milliseconds for n-times
//lsauer.com, 2012 lo sauer
//description: intervalCallNtimes; counter after nth time clearinterval; bind a function to a certain scope using 'intervalCall'
//requires: intervalCall, see: https://gist.github.com/lsauer/cf70e65c208cc311ce97
//@param fntimes: an integer-Number or function to control the number of invocations of the callback-counter-function:'fntimes'
// fntimes is passed an integer Number-counter, starting at 1;
//@param fn: the function to be invoked
//@param tm: timeout in milliseconds
//@param scope: scope in which the function should be invoked
//-> examples are provided below
function intervalCallNtimes(fntimes, fn, tm, scope){
@lsauer
lsauer / exception_handler.js
Created September 23, 2014 07:24
Javascript: Lean Exception handler
/**
* lsauer, 2013
* Lean handler for exception reporting; stdout is set by default to console.log
* @param {exc} exc an Exception instance of Error, containing a message and stack property
* @param {exc} stdOut A variadic function for error reporting. By default: console.log
* @return undefined
*/
var exceptionHandler = function(exc, stdOut){
var stdOut = stdOut || function() { console.log.apply(console, arguments) };
if(stdOut instanceof Function){
@lsauer
lsauer / global-scope-finding-setting.js
Created February 5, 2015 10:12
find and set the globalObject in JavaScript
"use strict";
if(!this.hasOwnProperty('globalScope')){
var globalScope;
try {
globalScope = Function('return this')();
}catch(ex){
//extend else-if cases for other globalObject-names as needed...
if(this && this.hasOwnProperty && this.hasOwnProperty('window')){
globalScope = window;
}else{
@lsauer
lsauer / php array merge by value
Created September 6, 2011 07:35
PHP: Array_merge by value, or array merge by values and keys
/**
L. Sauer,2011
license: public domain
http://xhr2.blogspot.com/2011/09/php-arraymerge-by-value-or-array-merge.html
*/
function array_merge_values_explode(){
$args = func_get_args();
$elem = array();
$delim = strlen(end($args))<=2 ? array_pop($args) : ',';
@lsauer
lsauer / gist:1197178
Created September 6, 2011 10:06
SyntaxHighlighter-script Render Fallback
//L.Sauer 2011; Public Domain
//renders code even without SyntaxHighlighter present
//see http://xhr2.blogspot.com/2011/09/alexgorbatchevcom-down-changing.html
//dp is the typical SyntaxHighlighter object;
//use the class 'shFallback' for styling the fallback <pre>-tag
if(typeof dp === 'undefined' ){
(function(){
var els = document.getElementsByTagName('script');
var elClass = null; //or e.g. class 'shFallback'
for(var i in els) {
@lsauer
lsauer / gist:1197340
Created September 6, 2011 11:45
ANSI C Determine the sign of a variable
( a >= 0 && ~a >= 0 )
First statement ensures that the variable is positive, the second ensures that no sign-bit is flipped.
@lsauer
lsauer / gist:1208350
Created September 10, 2011 14:16
JavaScript: Simple multi-timer for logging performance of an html page
function j2timer(e){
window.tdiff || (window.tdiff = []);
window.tdlog || (window.tdlog = []);
window.fnred || (window.fnred = function(a,b){return a-b;});
//toogle statement
if( (tdiff.length+1) % 2){
tdiff.push( Date.now());
return;
}
@lsauer
lsauer / gist:1209992
Created September 11, 2011 19:18
OnBlur will not fire when changing onFocus to onKeyUp, onKeyPress, onKeyDown,...
The following code will do just what you would expect (a css rule for the element's id is applied).
<input id="searchCmpnd" onClick="this._originalWidth = this.style.width; this.style.width='50%';" onBlur="this.style.width = this._originalWidth;" />
However when the onClick is changed to onKeyUp, onKeyPress, onKeyDown it will expand but not retract. This is because the element is not marked focused, or because the event order got messed up (in Chrome >12).
Include this.focus();
<input id="searchCmpnd" onClick="this._originalWidth = this.style.width; this.focus(); this.style.width='50%';" onBlur="this.style.width = this._originalWidth;" />