Skip to content

Instantly share code, notes, and snippets.

View balanza's full-sized avatar

Emanuele De Cupis balanza

View GitHub Profile
//this is row data coming from db
var dataset = [{
firstname: 'John',
lastname: 'Doe',
birth: '1986-02-09',
languages: ['en'],
sex: 'm'
}, {
firstname: 'Maria',
lastname: 'Rossi',
//those two instructions are equivalent
_.map(myArray, function(e){});
_(myArray).map(function(e){});
_.chain(obj)
.map(function(e){
//my mapping operation
})
.reduce(function(m, e){
//my reducing operation
})
.filter(function(e){
//guess what?
})
var obj = ['mario', 'luigi'];
var lambda = function(elem){
alert('Thanks ' + elem + ' but the princess is in another castle');
};
_.each(obj, lambda);
_.each(['mario', 'luigi'], function(elem){
alert('Thanks ' + elem + ' but the princess is in another castle');
});
@balanza
balanza / alloy.jmk
Last active March 14, 2017 01:25
Alloy compile hook for reenginering file structure of a project
task("pre:compile", function(event, logger) {
//a decorator for path.join that consider arrays as arguments
function superJoin() {
var args = Array.prototype.slice.call(arguments);
var p = [];
_.each(args, function(e) {
"config": {
"localhost": "191.191.24.249",
"ts_port": "3000",
"geny_s4": "Samsung Galaxy S4 - 4.3 - API 18 - 1080x1920"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"android:s4": "appc ti build -p android --device-id \"$npm_package_config_geny_s4\"",
"android:s4:ts": "appc ti build -p android -d ./shadow/ --device-id \"$npm_package_config_geny_s4\"",
@balanza
balanza / alloyView.xml
Created July 27, 2015 15:04
Templated Alloy component
<!-- that's the pursued implementation -->
<Alloy>
<MyComponent ns="require('myui')" id="mc1" foo="bar">
<Label>That's my precious content!</Label>
</MyComponent>
<MyComponent ns="require('myui')" id="mc2" foo="bar">
<Label>Another precious content!</Label>
</MyComponent>
</Alloy>
@balanza
balanza / log
Created July 15, 2015 14:26
Error trace from console
[TRACE] error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't move temporary file: /Users/emanuele/Documents/Workspace/titanium/kleur2/build/iphone/build/Debug-iphoneos/Kleur.app/Kleur to file: /Users/emanuele/Documents/Workspace/titanium/kleur2/build/iphone/build/Debug-iphoneos/Kleur.app/Kleur.lipo (Is a directory)
[TRACE] Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo emitted errors but did not return a nonzero exit code to indicate failure
[TRACE] GenerateDSYMFile build/Debug-iphoneos/Kleur.app.dSYM build/Debug-iphoneos/Kleur.app/Kleur
[TRACE] cd /Users/emanuele/Documents/Workspace/titanium/kleur2/build/iphone
[TRACE] export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/opt/local/bin:/opt/local/sbin:/Users/emanuele/.rvm/gems/ruby-2.1.2/bin:/Users/emanuele/.rvm/gems/ruby-2.1.2@global/bin:/Users/em
@balanza
balanza / parseUrl
Created January 27, 2015 15:20
Parse URL (including HTTP validation)
var parseUrl = function(url) {
var r = /^((http[s]?|ftp):\/)?\/?(([\w\-\.]+):([\w\-\.\$]+)@)?([^:\/\s]+)((\/\w+)*?(:([0-9]+))\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/;
var tmp = r.exec(url);
return {
original: tmp[0],
protocol: tmp[2],
username: tmp[4],
password: tmp[5],
host: tmp[6],