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-spinner.js
Created October 18, 2016 14:30
Cool node.js stdout spinner
const spinner = [ '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏' ];
for(var count=0;count<100000;count++) process.stdout.write(" "+spinner[ (count+1)% spinner.length ]+"\033[0G" ); // \033[0G | \r | \x1B[0G
@loretoparisi
loretoparisi / object+deepClone.js
Created October 7, 2016 10:38
Deep Clone a JavaScript Object
function deepClone(obj) {
var copy;
var i;
var len;
if (!obj || typeof obj !== 'object') {
return obj;
}
if (obj instanceof Array) {
@jovianlin
jovianlin / get_available_gpus.py
Created October 3, 2016 09:58
Get List of Devices in TensorFlow
from tensorflow.python.client import device_lib
def get_available_gpus():
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos if x.device_type == 'GPU']
get_available_gpus()
@romcaname
romcaname / postman-response-time-metrics.js
Last active July 4, 2022 12:28
a postman script to calculate the response time average and standard deviation of a request
function standardDeviation(values, avg) {
var squareDiffs = values.map(value => Math.pow(value - avg, 2));
return Math.sqrt(average(squareDiffs));
}
function average(data) {
return data.reduce((sum, value)=>sum + value) / data.length;
}
if (responseCode.code === 200 || responseCode.code === 201) {
@loretoparisi
loretoparisi / phantomjs+waitForCondition.js
Created September 14, 2016 15:16
Phantomjs example of wait For Page Document condition
/**
* Phantomjs example wait For Page Document condition
* @author Loreto Parisi (loretoparisi at gmail dot com )
*/
(function() {
/**
* Delayed wait on a condition
*/
var Delay = function() {
@hagerty
hagerty / CosmiQNet.py
Last active March 20, 2023 10:29
Fully convolutional neural network for classifying building from 3-band and 8-band imagery
#Generator
with tf.device(gpu):
x8 = tf.placeholder(tf.float32, shape=[None, FLAGS.ws, FLAGS.ws, 8]) # 8-band input
x3 = tf.placeholder(tf.float32, shape=[None, scale * FLAGS.ws, scale * FLAGS.ws, 3]) # 3-band ipnput
label_distance = tf.placeholder(tf.float32, shape=[None, FLAGS.ws, FLAGS.ws, 1]) # distance transform as a label
for i in range(layers):
alpha[i] = tf.Variable(0.9, name='alpha_' + str(i))
beta[i] = tf.maximum( 0.0 , tf.minimum ( 1.0 , alpha[i] ), name='beta_'+str(i))
bi[i] = tf.Variable(tf.constant(0.0,shape=[FLAGS.filters]), name='bi_'+str(i))
@loretoparisi
loretoparisi / object+map+filter.js
Created September 14, 2016 09:50
JavaScript map and filter object extensions
/********************
* Object modifiers
********************/
/**
* Object.mapObject(value,key)
* Map Object properties
* @return object Copy of this object
*/
if( typeof( Object.mapObject ) == 'undefined') {
@quadrismegistus
quadrismegistus / gensim_word2vec_procrustes_align.py
Last active November 16, 2023 01:57
Code for aligning two gensim word2vec models using Procrustes matrix alignment. Code ported from HistWords <https://github.com/williamleif/histwords> by William Hamilton <[email protected]>. [NOTE: This code is DEPRECATED for latest versions of gensim. Please see instead this updated version of the code <https://gist.github.com/zhicongchen/9e23…
def smart_procrustes_align_gensim(base_embed, other_embed, words=None):
"""Procrustes align two gensim word2vec models (to allow for comparison between same word across models).
Code ported from HistWords <https://github.com/williamleif/histwords> by William Hamilton <[email protected]>.
(With help from William. Thank you!)
First, intersect the vocabularies (see `intersection_align_gensim` documentation).
Then do the alignment on the other_embed model.
Replace the other_embed model's syn0 and syn0norm numpy matrices with the aligned version.
Return other_embed.
@loretoparisi
loretoparisi / tcp_listen.sh
Created September 13, 2016 12:51
Get LISTEN TCP connections on localhost
#!/bin/bash
netstat -atn | grep LISTEN | grep "127.0.0.1"
@loretoparisi
loretoparisi / roundrobin.js
Created September 5, 2016 12:42
Round robin scheduler in JavaScript - https://www.npmjs.com/package/roundrobin
function(n, ps) {
const DUMMY = -1;
var rs = []; // rs = round array
if (!ps) {
ps = [];
for (var k = 1; k <= n; k += 1) {
ps.push(k);
}
} else {
ps = ps.slice();