This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | |
$.getJSON('b8irg1.json', function(data) { console.log(data);}); | |
will only contain an responseText property but not the JSON.parse'd data appended if the JSON file contains comments of the kind '// or /*...*/' | |
Note tried with jquery 1.6.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author: lsauer.com | |
//Data is in the form | |
//[ ["JOEBRA","Doeduardo","9.9.1999","Midwaystreet 12","1160 Vienna", "Austria" ],...] | |
//if you need the name fully anonymized shuffle the name before substr or calculate a Soundex of it | |
for(i=0; i<x.autpolData.length; i++){ | |
tmp[i] = [].concat(x.autpolData[i][1].substr(0,4), x.autpolData[i][2].split('.')[2], x.autpolData[i].slice(3) ) | |
} | |
//["Doed", "1948", "Midwaystreet 12", "1160 Vienna", "Austria" | |
//the address is resolved to GPS lat/long -> see my scripts_n_snips folder | |
//often times JS is faster and more powerful than an editor with RegExp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#author: lo sauer 2011 - lsauer.com | |
#demonstrating the difference in RegEx engines | |
Python: | |
import re | |
a="123 test 42 <!-- comment 345 commentEnd --> 678 test2 348" | |
filter(None, re.findall('(?:\<\!--.+\d+.+--\>)|(\d+)',a)) | |
#With RegEx lookbehinds; for demonstration only - not very practical (slow!) | |
re.findall('(\d+)(?!(?:[^<]+|<(?!!--))*-->)',a)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//lo sauer 2011 - lsauer.com | |
//join() is by default: join(',') | |
[1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,,8,,,-2].filter(String).join() | |
>>>"1,2,3,3,0,4,4,5,6,8,-2" | |
//same result for: filter(function(){return 1}); | |
[1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,,8,,,-2].filter(function(){return 1}).join() | |
>>>"1,2,3,3,0,4,4,5,6,8,-2" | |
//to conveniently eliminate null-elements... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author: lo sauer 2011 - lsauer.com | |
//implementation of PHP's trim | |
//see http://php.net/manual/en/function.trim.php | |
//bug: doesn't work with ']' in the charlist | |
//@param: charlist <string> | |
String.prototype.phptrim = function(s) | |
{ | |
if(0==arguments.length) | |
return this.valueOf().trim(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author: lo sauer 2011 | |
//given for instance, is a text with placeholders of which only the value is to be captured | |
//JS's 'match' ignores the non-capture group (?:...), for instance in a global search | |
str = "Hello I am {{name}}. Is it already the {{date}}"; | |
str.match(/(?:\{{2})([a-z0-9]*)(?:\}{2})/i); | |
>>>["{{name}}", "name"] | |
str.match(/(?:\{{2})([a-z0-9]*)(?:\}{2})/gi); | |
>>>["{{name}}", "{{date}}"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author: lo sauer 2011, lsauer.com | |
//description: Forcing JSON array notation on array-like object (i.e. arguments, DOMCollection) | |
//application: e.g. JSON-RPC | |
//Take for instance this simple function, which returns a pure JS object notation | |
function x(){console.log(JSON.stringify(arguments))} | |
x(1,2,3,"sfdsf", [1,2,3], {1:2}) | |
>>>[{"0":1,"1":2,"2":3,"3":"sfdsf","4":[1,2,3],"5":{"1":2}}] | |
//There is no straightforward Array typecasting in JS; Array() will nest the object in an array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author:lo sauer 2011; lsauer.com | |
"DOM Storage is the name given to the set of storage-related features" | |
see here: https://developer.mozilla.org/en/DOM/Storage | |
==LOCAL STORAGE/SESSION STORAGE== | |
Cookies result in HTTP overhead | |
HTML5 solutions: | |
Local Storage & Session Storage | |
*Hash key/value store | |
*5MB of data across browsers / per site (W3C Specification) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//instructions are especially for mysql: | |
//lo sauer, 2011 | |
1. create the database: 'CREATE DATABASE `enzymes`;' | |
2. now either select the database with 'USE `enzymes`;' or put the same command at the beginning of your sql-file. | |
in the latter case run sqlimport which is a shortcut for the more powerful command LOAD DATA INFILE http://dev.mysql.com/doc/refman/5.1/en/load-data.html | |
' mysqlimport -u root -p --local enzymes enzymes.sql' | |
Or in mysql (e.g. mysql -u root -p) you can use the LOAD DATA INFILE Command |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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, |