Skip to content

Instantly share code, notes, and snippets.

View Onheiron's full-sized avatar

Carlo Moretti Onheiron

View GitHub Profile
@Onheiron
Onheiron / promise-ext.js
Last active March 16, 2018 16:56
Some utility extensions for Node.js Promise to help combine different Promises in a cleaner and more readable way
/**
* Promise plugin aggregate(promiseMap).
*
* Creates a Promise that maps the incremental results of given promises in an Object with keys given by the input map.
* Errors if any of the given promises erros.
*
* Examples:
*
* Promise.aggregate({
* cats: Promise.resolve(['Felix', 'Garfield']),
@Onheiron
Onheiron / toJSON.js
Created November 11, 2012 16:07
Form 2 JSON - jQuery Plugin
$.fn.toJSO = function () {
var obj = {},
$kids = $(this).children('[name]');
if (!$kids.length) {
return $(this).val();
}
$kids.each(function () {
var $el = $(this),
name = $el.attr('name');
if ($el.siblings("[name=" + name + "]").length) {
@Onheiron
Onheiron / Form2JSON.js
Created July 3, 2012 08:01
Gets datas form your HTML form and generates a JSON Object out of it!
function toJSON(node){
if(!$(node).children().length) return $(node).val();
var json = new Object();
$(node).children('[name]').each(function(){
if($(this).siblings("[name="+$(this).attr('name')+"]").length){
@Onheiron
Onheiron / arrayToXML.php
Created June 30, 2012 22:29
PHP - ArrayToXML Converter
<?php
function arrayToXML($array,$parent,$xml=null){
$index = 0;
if($xml == null){
$xml = new SimpleXMLElement("<".$parent."/>");