Skip to content

Instantly share code, notes, and snippets.

View loretoparisi's full-sized avatar
🐍
NightShift

Loreto Parisi loretoparisi

🐍
NightShift
View GitHub Profile
/** Fetch user agents by class from http://ua.theafh.net/ */
function UserAgents () {
var COL_UA=1;
var COL_CLASS=3;
this.list=[];
this.Class='';
this.parse = function(Class) {
this.list=[];
var self=this;
this.Class=Class;
@loretoparisi
loretoparisi / spotify+users+playlist-search.js
Last active April 13, 2016 00:35
It search Spotify Users having Playlists with given search terms.
// Simple XMLHttpRequest
// based on https://davidwalsh.name/xmlhttprequest
var SimpleRequest = {
call: function(what, response) {
var request;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
@loretoparisi
loretoparisi / Promise+Node+Process+Spawn.js
Created April 13, 2016 00:31
Spawn processes in Node with Promise.All
var cp = require('child_process');
var promiseAll = function(items, block, done, fail) {
var self = this;
var promises = [],
index = 0;
items.forEach(function(item) {
promises.push(function(item, i) {
return new Promise(function(resolve, reject) {
if (block) {
block.apply(this, [item, index, resolve, reject]);
@loretoparisi
loretoparisi / promise+settle.js
Created April 13, 2016 17:31
Promise.settle implementation
// ES6 version of settle
Promise.settle = function(promises) {
function PromiseInspection(fulfilled, val) {
return {
isFulfilled: function() {
return fulfilled;
}, isRejected: function() {
return !fulfilled;
}, isPending: function() {
// PromiseInspection objects created here are never pending
@loretoparisi
loretoparisi / spotify_notifications.py
Created April 29, 2016 09:43
Listen Spotify MacOS notifications via Cocoa NSDistributedNotificationCenter
'''
Listen Spotify MacOS App for Notifications
It currently supports
`com.spotify.client.PlaybackStateChanged`
@author: loretoparisi at gmail dot com
'''
import Foundation
import json
from AppKit import *
from PyObjCTools import AppHelper
@loretoparisi
loretoparisi / jquery+table.js
Created May 4, 2016 15:32
JQuery HTML Table to CSV
jQuery.fn.table2CSV = function(options) {
var options = jQuery.extend({
separator: ',',
header: [],
delivery: 'popup' // popup, value
},
options);
var csvData = [];
var headerArr = [];
@loretoparisi
loretoparisi / table+csv.js
Created May 4, 2016 15:35
HTML Table to CSV in JavaScript
function exportTableToCSV($table, filename, delimiter) {
var $headers = $table.find('tr:has(th)'),
$rows = $table.find('tr:has(td)')
// Temporary delimiter characters unlikely to be typed by keyboard
// This is to avoid accidentally splitting the actual contents
,
tmpColDelim = String.fromCharCode(11) // vertical tab character
,
tmpRowDelim = String.fromCharCode(0) // null character
// actual delimiter characters for CSV format
/* This work is licensed under Creative Commons GNU LGPL License.
License: http://creativecommons.org/licenses/LGPL/2.1/
Version: 0.9
Author: Stefan Goessner/2006
Web: http://goessner.net/
*/
function xml2json(xml, tab) {
var X = {
toObj: function(xml) {
/* This work is licensed under Creative Commons GNU LGPL License.
License: http://creativecommons.org/licenses/LGPL/2.1/
Version: 0.9
Author: Stefan Goessner/2006
Web: http://goessner.net/
*/
function json2xml(o, tab) {
var toXml = function(v, name, ind) {
var xml = "";
/* JSONPath 0.8.0 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*/
function jsonPath(obj, expr, arg) {
var P = {
resultType: arg && arg.resultType || "VALUE",
result: [],
normalize: function(expr) {