Skip to content

Instantly share code, notes, and snippets.

View fabriceleal's full-sized avatar
😫
meh

Fabrice Ferreira Leal fabriceleal

😫
meh
  • Leiria, Portugal
View GitHub Profile
// "Extend" the EventEmitter like this:
var EventEmitter = require('events').EventEmitter;
EventEmitter.prototype.once = function(events, handler){
// no events, get out!
if(! events)
return;
// Ugly, but helps getting the rest of the function
@fabriceleal
fabriceleal / letmacro.js
Created November 15, 2012 21:40
js let macro
macro $let {
case ( $($id:ident = $val:expr) (,) ... ) $body => {
/*(function(){
$(var $id = $val;) ...
var ____r = (function() $body)();
return ____r;
})()*/
(function ($id (,) ...) $body)($val (,) ...)
}
}
@fabriceleal
fabriceleal / gist:4081503
Created November 15, 2012 21:41
js function-shortcut macro
macro λ {
case $params $body => {
(function $params $body)
}
case $name:ident $params $body => {
(function $name $params $body)
}
}
var a = λ (a) {
@fabriceleal
fabriceleal / gist:4090540
Created November 16, 2012 20:19
js K combinator
macro $K {
case ($literal) => {
(function(){
return $literal;
})
}
case (function $params $body) => {
(function(){
return function $params $body;
})
@fabriceleal
fabriceleal / gist:4133039
Created November 22, 2012 21:45
functional repeat
Number.prototype.repeat = function(doSomething){
var last = Math.floor(this);
var ret = new Array(last);
for(var i = 0; i < last; ++i){
ret[i] = doSomething();
}
return ret;
};
// Example:
@fabriceleal
fabriceleal / gist:4133116
Created November 22, 2012 22:12
Javascript macro for the Y combinator, using sweet.js
// y-combinator
macro $y {
case ( $var ) => {
function(){
return function(f){
return f(f)
}(function(f){
return $var(function(x){
return f(f)(x);
})
@fabriceleal
fabriceleal / gist:4136290
Created November 23, 2012 16:12
Microsoft.SqlServer.Smo - log database size to file
# You MUST have sql management tools installed
# ("...dll", "...dll", "...dll") | foreach { [System.Reflection.Assembly]::LoadFile($_) }
# Load these. Probabily missing in GAC; load with absolute path
[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll")
#[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll")
#[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\
# Fill those:
@fabriceleal
fabriceleal / gist:4240254
Created December 8, 2012 13:20
Untargz .tar.gz
# Gzip
tar -zxf <archive_name.tar.gz>
# Bzip
tar -jxf <archive_name.tar.bz2>
# -z Gzip
# -x Extract
# -f use archive file
@fabriceleal
fabriceleal / gist:4240436
Created December 8, 2012 14:23
file system usage
du -h
# -h: Human readable sizes
@fabriceleal
fabriceleal / gist:4245410
Last active October 13, 2015 19:37
Grant permission to endpoint (host + port)
netsh http add urlacl url=http://127.0.0.1:7654/ user=DOMAIN\user