Skip to content

Instantly share code, notes, and snippets.

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

Alex piscis

🧱
¯\_(ツ)_/¯
View GitHub Profile
@piscis
piscis / express htaccess example
Created January 15, 2011 10:00
Protecting express via connect basic auth plugin
var express = require('express');
var app = express.createServer();
// User validation
var auth = express.basicAuth(function(user, pass) {
return (user==pass) ? true : false;
},'Admin Area');
app.get('/hello', auth, function(req,res) {
res.writeHead("200");
@piscis
piscis / copy.js
Created April 13, 2011 16:14 — forked from c4milo/copy.js
// fs.copy(src,dst) && fs.copySync(src,dst)
var copy = function copy(src, dst, callback) {
var self = this;
if(!callback) {
callback = function(){};
}
self.on('error', function(err) {
@piscis
piscis / gist:1031244
Created June 17, 2011 11:23
create a shortlink
curl http://crop.io/v1/c/?lurl=http%3A//www.example.org
(function($) {
var tmpl = '';
tmpl += '<div class="ui-grid-b">';
tmpl += '<div class="ui-block-a" id=""><div class="ui-bar ui-bar-c" style="height:120px"><a href="#overview" data-role="button" class="ui-btn-right" data-icon="delete">Overview</a></div></div>';
tmpl += '<div class="ui-block-b"><div class="ui-bar ui-bar-c" style="height:120px"><a href="#device" data-role="button" class="ui-btn-right" data-icon="delete">Device</a></div></div>';
tmpl += '<div class="ui-block-c"><div class="ui-bar ui-bar-c" style="height:120px"><a href="#mapview" data-role="button" class="ui-btn-right" data-icon="delete">Map View</a></div></div>';
tmpl += '<div class="ui-block-a"><div class="ui-bar ui-bar-c" style="height:120px">A</div></div>';
tmpl += '<div class="ui-block-b"><div class="ui-bar ui-bar-c" style="height:120px">B</div></div>';
@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_);
@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: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: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: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: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";