Skip to content

Instantly share code, notes, and snippets.

Lorenz Lo Sauer lsauer

Block or report user

Report or block lsauer

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
@lsauer
lsauer / php array merge by value
Created Sep 6, 2011
PHP: Array_merge by value, or array merge by values and keys
View php array merge by value
/**
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 Sep 6, 2011
SyntaxHighlighter-script Render Fallback
View gist:1197178
//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 Sep 6, 2011
ANSI C Determine the sign of a variable
View gist:1197340
( 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 Sep 10, 2011
JavaScript: Simple multi-timer for logging performance of an html page
View gist:1208350
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 Sep 11, 2011
OnBlur will not fire when changing onFocus to onKeyUp, onKeyPress, onKeyDown,...
View gist:1209992
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;" />
@lsauer
lsauer / gist:1210023
Created Sep 11, 2011 — forked from timbroder/gist:1209944
insert update url rewrite
View gist:1210023
#INSERT INTO `core_url_rewrite` (`store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`)
SELECT 1 AS `store_id`,
`sub`.`category_id`,
`sub`.`entity_id` AS `product_id`,
CONCAT('product', '/', `entity_id`, '/', `category_id`) AS `id_path`,
`value` AS `request_path`,
CONCAT('catalog/product/view/id/', `entity_id`, '/category/', `category_id`) AS `target_path`,
1 AS `is_system`
FROM
(SELECT
@lsauer
lsauer / gist:1213403
Created Sep 13, 2011
Submitting a browser-like HTTP request
View gist:1213403
#L sauer 2011, public domain
def main():
import urllib2
furl = urllib2.Request('http://www.mypacm.us.gov/bin/www_bget?one=two')
furl.add_header('Referer', 'http://www.mypacm.us.gov/')
furl.add_header('User-agent', 'Mozilla/5.0 AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.35 Safari/535.1')
furl.add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
furl.add_header('Accept-Encoding', 'gzip,deflate,sdch')
furl.add_header('Accept-Language', 'en-US,en;q=0.8')
#furl.add_header('Origin', 'http://www.mypacm.us.gov/bin/')
@lsauer
lsauer / gist:1221325
Created Sep 16, 2011
Javascript word frequency counter - word histogramm
View gist:1221325
//l.sauer 2011, public domain
//returns a hash table with the word as index and frequency as value; good for svg / canvas -plotting or other experiments
//[:punct:] Punctuation symbols . , " ' ? ! ; : # $ % & ( ) * + - / < > = @ [ ] \ ^ _ { } | ~
var wordcnt = function(id){
var hist = {}, words = document.getElementById(id).innerText.split(/[\s*\.*\,\;\+?\#\|:\-\/\\\[\]\(\)\{\}$%&0-9*]/)
for( i in words)
if(words[i].length >1 )
hist[words[i]] ? hist[words[i]]+=1 : hist[words[i]]=1;
return hist;
};
@lsauer
lsauer / gist:1238036
Created Sep 23, 2011
Social Box for websites with Facebook, Twitter and Google plus one - HTML 4 / 5
View gist:1238036
<style type="text/css">
.socialBoxV, .socialBoxH { {
float: right;
margin: 15px 20px 0 0;
padding: 7px 7px 7px 14px;
background-color: #FCF6C4;
border-radius: 5px;
-o-transition: all 0.7s linear;
-moz-transition: all 0.7s linear;
@lsauer
lsauer / gist:1238371
Created Sep 23, 2011
Color and grey palette in PHP and Javascript
View gist:1238371
//author: unknown/ extended by Lo Sauer (2000); Codebase yr2000
//descr: Color and grey palette in PHP with Javascript interaction
<script language="JavaScript">
var coRed=127;coGreen=127;coBlue=255; // Original color
var Hex=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
function rgb2hex(cRed,cGreen,cBlue){
cColor=Hex[Math.floor(cRed/16)]+Hex[cRed%16]+Hex[Math.floor(cGreen/16)]+Hex[cGreen%16]+Hex[Math.floor(cBlue/16)]+Hex[cBlue%16];
You can’t perform that action at this time.