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 / gist:1278532
Created October 11, 2011 16:10
PHP accessing numeric properties from an object to allow e.g. obj(explode("-","my-test-test"))->_0
//lo sauer, 2011 - lsauer.com
PHP variable names can't start with a digit. As such non-associative array conversion can pose a problem.
Additionally stdClass does not implement ArrayAccess - as PHP's base class.
//note: this is not serialized php code
$var = stdClass Object
(
[0] => stdClass Object
(
['my'] => 1442,
@lsauer
lsauer / gist:1285096
Created October 13, 2011 18:45
Conversion Recipe for cooking SQL from csv, tsv,...
csv,tsv to SQL conversion recipe
1.remove the first row split(by either tab or ,) and store in an array (field-header row)
e.g. ('Compound_id', 'Compound_common_name', 'Compound_synonyms', 'Molecular_weight',
'Chemical_formula', 'Smiles', 'Links', 'EC', 'Reaction_equation', 'Pathway'),
2.replace (in this order):
' -> \n
tab/, -> ', '
\n -> '),\n(NULL, '
@lsauer
lsauer / gist:1295276
Created October 18, 2011 12:06
PHP - ZEND like URI Builder Class for RESTful services
<?php
//author:lo sauer,2011 - lsauer.com - PHP - ZEND like URI Builder Class for RESTful services
//license: MIT license
//description: url builder class; allows object oriented setting of parameters etc, without relying on a big frameworks like ZEND
//purpose: emulating ZEND-like url-setting as shown for instance here: http://www.ibm.com/developerworks/web/library/x-phpwikipedia/?ca=drs-
//to show preformatted text
header("Content-Type: text");
@lsauer
lsauer / gist:1296724
Created October 18, 2011 21:06
CSS one colum fixed the other width set to fill percent % of the remaining area
<script>
// by lo sauer, 2011 - lsauer.com
// two div's or more are set such that the first is set to a fixed width, and the rest should be percent e.g. space filling
// container: <div id="container" style="width:700px;"> [div1] [div2] [divn...]</div>
// leftmost div: <div style="float:left; width:80px;>content</div>
// rightmost div: <div style="float:left; margin-right:80px; width:100%;>content</div>
// correct width a counter-margin, according to the total fixed-width; 80px in the example above
// below is an example, which you can see here: http://pastehtml.com/view/bb1d7ub83.html
// also note that in CSS, 'summarized' padding and margin settings start at the top, and proceed counter clockwise: top, right, bottom, left
// e.g. padding:0px 2px 2px 0px;
@lsauer
lsauer / gist:1297805
Created October 19, 2011 09:12
DOM based: Converting BioCyc, *Cyc superpathways into JSON data
// lo sauer,2011 - dual license: your driver's license or public domain
// descr: quick hack for compiling BioCyc, *Cyc superpathways into JSON data
// milage may vary... try it for instance on: http://biocyc.org/ARA/NEW-IMAGE?object=Super-Pathways
// NOTE: heed this project: https://github.com/lsauer/json2sql (TBA soon) -> allows reorganization of higher order data structures into relational SQL tables
(function(self){
var _set = [],
_el = self.getElementsByClassName('ecoparagraph')[3].getElementsByTagName('a');
for(var i in _el){
var n = _el[i];
if(!n.getAttribute)
@lsauer
lsauer / License
Created October 24, 2011 10:39
Simple english language ordinal for an integer e.g. 1st, 2nd, 12th, 25th - 'map-reduce logic'
Dual licensed: BSD or Your Driver's License
1.<INSERT YOUR DRIVER'S LICENSE + MUGSHOT HERE>
2.<BSD LICENSE>
Copyright (c) 2011 lo sauer.
All rights reserved.
Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
@lsauer
lsauer / gist:1316220
Created October 26, 2011 12:36
JavaScript's parseInt estimates the base of the Number without a base defined via the second parameter... & Number padding
//lo sauer, 2011; lsauer.com - licensed under the "WTF's a licence?"-license
// parseInt() can show curious behavior; If a string is passed, without a second parameter
// (which takes the proper base of the number), parseInt may return unexpected numbers.
// For example parseInt('010') returns 8, not 10. Set the base to get the correct decimal result.
parseInt('0000010'); // returns 8! (FF>3, Chrome,...)
>8
parseInt('0000010', 10); // returns 10, because the base is set to decimal
>10
+'0000010'
@lsauer
lsauer / gist:1316434
Created October 26, 2011 13:58
String / Number padding in JavaScript several methods and benchmark
//lo sauer, 2011; "what's a license?"-license
//String / Number padding in JavaScript
// performance seems to be equivalent, i.e. slice is an alias for substr http://jsperf.com/padding6000
// ===Method 1===:
var str = "test";
// padding length = pad.length
var pad = '0000000000000000';
pad.length
> 16
@lsauer
lsauer / gist:1321158
Created October 27, 2011 23:03
JavaScript testing for a binary bitcode String as part of the islib-project
// lo sauer, lsauer.com - JavaScript testing for binary String as part of my 'islib'-project
// description: For a parser I need to first make sure whether the character set of the input is a
// standard-printable ASCII-charset i.e. text
(is={}).Binary = function (o) { if( typeof o !== 'string') return false; return !(RegExp("^([\x20-\x7F]+)$").test(o)); }
is.Binary("Hello World!")
false
is.Binary("Hello World!\0x12")
true
is.Binary("Hello World! - Àéʱ")
true
@lsauer
lsauer / gist:1461642
Created December 11, 2011 17:20
jquery .toggle API examples - and direct toggling
//lo sauer, 2011; lsauer.com
//jquery toggle accepts functions and pools these;
//These functions ('actions') are then cycled through upon each event-based invocation
//Variants:
//.toggle( [duration] [, easing] [, callback] )
//.toggle( [duration] [, callback] )
//.toggle( showOrHide )
//#imgtagtop is a simple image: <img src="..." id="imgtagtop">