Skip to content

Instantly share code, notes, and snippets.

View loretoparisi's full-sized avatar
🐍
NightShift

Loreto Parisi loretoparisi

🐍
NightShift
View GitHub Profile
@loretoparisi
loretoparisi / node-phantom+waitUntil.js
Created May 20, 2016 16:25
A node phantom example to run a promise for evaluate a document condition Raw
(function() {
var Crawler,phantom,cheerio;
cheerio = require("cheerio"),
phantom = require('phantom');
var waitUntil = function(asyncTest) {
return new Promise(function(resolve, reject) {
function wait() {
@loretoparisi
loretoparisi / tone-analyzer-example-response.json
Created May 31, 2016 14:17
Example of IBM Watson Tone Analyzer Response
{
"document_tone": {
"tone_categories": [
{
"tones": [
{
"score": 0.308012,
"tone_id": "anger",
"tone_name": "Anger"
},
@loretoparisi
loretoparisi / tone-analyzer-example-response-sentences_tones.json
Last active June 1, 2016 08:29
IBM Watson Tone Analyzer Example of JSON Response with document and sentences levels
{
"document_tone": {
"tone_categories": [
{
"tones": [
{
"score": 0.246262,
"tone_id": "anger",
"tone_name": "Anger"
},
@loretoparisi
loretoparisi / promise-all-coffeescript.coffee
Created July 9, 2016 15:14
Promise all in CoffeeScript
subset = [
'item1'
'item2'
'item3'
]
# uniform distribution of wait times
waitTimes = arrayRangeMap(subset.length, ->
getRandomArbitrary(0.1, 0.3, 3) * 1000
)
Q = PromiseAllP(subset, executionBlock, waitTimes)
(function twitterRemoveCharLimit() {
function hasClass(ele, cls) {
return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
ele.className = ele.className.replace(reg, ' ');
}
let serialise = function(obj) {
if (typeof obj != 'object') return obj;
let pairs = [];
for (let key in obj) {
if (null != obj[key]) {
pairs.push(encodeURIComponent(key)
+ '=' + encodeURIComponent(obj[key]));
}
}
return pairs.join('&');
@loretoparisi
loretoparisi / olympic_rings.logo
Created August 1, 2016 19:55
Olympic Rings in Logo compatibile with JSLogo Interpreter - http://www.calormen.com/jslogo/
@loretoparisi
loretoparisi / wgxpath+browser.js
Last active October 7, 2016 10:40
Wicked-Good-Xpath browser example
// inject Wicked-Good-Xpath
var script = document.createElement('script');
script.src = "https://github.com/google/wicked-good-xpath/releases/download/1.3.0/wgxpath.install.js";
document.getElementsByTagName('head')[0].appendChild(script);
script.onload=function() {
console.log("injected")
// install wgxpath
wgxpath.install()
// create expression
var expressionString = '//*[@class="word-and-pronunciation"]/h1';
@loretoparisi
loretoparisi / jsdom+wgxpath-cheerio+request.js
Created August 26, 2016 15:39
JSDOM + Wgxpath vs Cheerio + Request HTML Parsers
// wgxpath + jsdom
var wgxpath = require('wgxpath');
var jsdom = require('jsdom');
// cheerio + request
var cheerio = require('cheerio');
var request = require('request');
var url = 'http://www.merriam-webster.com/word-of-the-day';
var expressionString = '//*[@class="word-and-pronunciation"]/h1';
@loretoparisi
loretoparisi / pickle_load.py
Created August 31, 2016 14:06
Load a file with Picke
import pickle
file = open("~/.keras/datasets/imdb_full.pkl",'rb')
file = open(".keras/datasets/imdb_full.pkl",'rb')
object_file = pickle.load(file)
file.close()