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: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 / gist:1305056
Created October 21, 2011 21:40
Easiest way to find duplicate values in a JavaScript array - Native unique function implementation
//lo sauer, 2011; lsauer.com
/**
* I saw this thread: http://stackoverflow.com/questions/840781/easiest-way-to-find-duplicate-values-in-a-javascript-array
* The solutions above lacked the elegance that can be done a with map-reduce-like operations
* Since this implementation works with native functions, the speed is in most circumstances faster
* than any solution using scripted-logic
* Additionally, I needed to quickly filter duplicate url-entries for: http://lsauer.github.com/chrome-session-restore/
*/
//copy and paste: without error handling
Array.prototype.unique = function(){return this.sort().filter( function(v,i,o){if(i>=0 && v!==o[i-1]) return v;});}
@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 / InChi.js
Created October 25, 2011 14:13
Regular Expressions for validating SMILES, InChi, InChiKey
// International Chemical Identifier Regex, by lo sauer - lsauer.com
// Morphine InchI:
var x="InChI=1S/C17H19NO3/c1-18-7-6-17-10-3-5-13(20)16(17)21-15-12(19)4-2-9(14(15)17)8-11(10)18/h2-5,10-11,13,16,19-20H,6-8H2,1H3/t10-,11+,13-,16-,17-/m0/s1"
// applying an organic character-subset
// we could check for the length property, but in case of 0 matches 'null' is returned -> hence !!.. \ generally equal to Boolean(..)
!!x.trim().match(/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\/,pqbtmsih]{6,})$/ig)
>true
//generic:
x.trim().match(/^((InChI=)?[^J][0-9a-z+\-\(\)\\\/,]+)$/ig)
@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:1320437
Created October 27, 2011 18:45
A list of common HTTP header settings
// by jonas john, posted by lo sauer / lsauer.com; PUBLIC DOMAIN
// description: common http headers:
// Use this header instruction to fix 404 headers
// produced by url rewriting...
header('HTTP/1.1 200 OK');
// Page was not found:
header('HTTP/1.1 404 Not Found');
// Access forbidden: