Skip to content

Instantly share code, notes, and snippets.

View piscis's full-sized avatar
🧱
¯\_(ツ)_/¯

Alex piscis

🧱
¯\_(ツ)_/¯
View GitHub Profile
@piscis
piscis / gist:1779908
Created February 9, 2012 13:24
Prototype inheritance example
var util = require("util");
var A =function() {
// constructor
}
A.prototype.on = function() {
console.log('Call A: ON');
};
@piscis
piscis / Test drive
Created December 21, 2011 09:54
Parallel & serial directory walker
walk(process.env.HOME, function(err, results) {
if (err) throw err;
console.log(results);
});
@piscis
piscis / gist:1486675
Created December 16, 2011 16:17
Removes a class from html tag via javascript, this is usefull if you enhance user experiance via JS
<script type="text/javascript">
/* CSS to JS style detector */
document.getElementsByTagName("html")[0].className = document.getElementsByTagName("html")[0].className.replace( /(?:^|\s)no\-js(?!\S)/ , '' )
</script>
@piscis
piscis / proccess binding
Created December 15, 2011 15:51
Writing A Async Module +0.5.3
#include <v8.h>
#include <node.h>
#include <stdlib.h>
#include <errno.h>
using namespace node;
using namespace v8;
struct Test_req
{
@piscis
piscis / gist:1466115
Created December 12, 2011 09:14
Match ASCII chars via RegularExpression in Javascript
/**
* Small regular expression to match ASCII-chars between 32-126
*
* For a conversion table for ASCII chars see:
* http://de.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange
*/
var expr = /([\x20-\x7E]{1,})/gi;
var testString = "Foo Bar Barz";
var testString2 = "Foo Bar\tBarz";
@piscis
piscis / gist:1372991
Created November 17, 2011 11:56
Some KnockOut js data binding helper, to work a round a problem when setting values on in input fields via jQuery and knockout JS databinding
/**
* hasKeyExists
*
* Searches for a hierarchical combination of keys in a json object
*
* @{Object} JSON Object
* @{String} path seperated with "." for example level1.level2.foo
* @return {Boolean}
*/
var hashKeyExists = function(obj,path){
@piscis
piscis / gist:1370790
Created November 16, 2011 17:46
Walk a javascript hash recursive and check for key exists
var a = { a: { b: 1 } };
var b = ['a','b'];
var hashKeyExists = function(obj,path){
var keys = path.split('.');
var keyExists = function(obj,keyList){
var cur = keyList.shift();
@piscis
piscis / gist:1324540
Created October 29, 2011 14:51
handy little bash innodb table converter
for t in $(mysql --batch --column-names=false -e "show tables" dbname |grep -v "exclude_this");
do
mysql -e "alter table $t engine=InnoDB" dbname;
done
@piscis
piscis / gist:1311773
Created October 25, 2011 07:57
async example node (0.5.2+)
#include <v8.h>
#include <node.h>
#include <stdlib.h>
#include <errno.h>
using namespace node;
using namespace v8;
struct Test_req
{
@piscis
piscis / gist:1303926
Created October 21, 2011 14:00
Async Call
#define ASYNC_CALL(func, callback, ...) \
FSReqWrap* req_wrap = new FSReqWrap(); \
int r = uv_fs_##func(uv_default_loop(), &req_wrap->req_, \
__VA_ARGS__, After); \
assert(r == 0); \
req_wrap->object_->Set(oncomplete_sym, callback); \
req_wrap->Dispatched(); \
return scope.Close(req_wrap->object_);