Skip to content

Instantly share code, notes, and snippets.

View mrm8488's full-sized avatar
🏠
Working from home

Manuel Romero mrm8488

🏠
Working from home
View GitHub Profile
# Detect hardware
try:
tpu = tf.distribute.cluster_resolver.TPUClusterResolver() # TPU detection
except ValueError:
tpu = None
gpus = tf.config.experimental.list_logical_devices("GPU")
# Select appropriate distribution strategy
if tpu:
tf.config.experimental_connect_to_cluster(tpu)
tail -F firewall.log |while
read -r line;do printf
"\033[38;5;%dm%s\033[0m\n" $
((SRANDOM%255)) "Sline";done #
Random color per log line.
@mrm8488
mrm8488 / README.md
Created October 24, 2019 01:09 — forked from notwaldorf/README.md
ServiceWorker code to cache Tensorflow model shards.

ServiceWorker code to cache TensorFlow model shards.

One of the problems I have when testing giant TensorFlow models in TensorFlow.js is that they're huge (like 500 MB) and they take forever to download, every time I refresh the page. This is how I setup my ServiceWorker code so that at least in testing I only have to download the model once, and then it's saved in the cache for the next time.

@mrm8488
mrm8488 / from_callbacks_to_util.promisify().js
Last active March 21, 2019 19:25
Here we can see how Node.js 8 allow us to promisify I/O functions that return callbacks (without 3pp modules such as Q or Bluebird)
/* AUTHOR: mrm8488@gmail.com */
/* Node.js v8 */
const fs = require('fs');
/* BEFORE util.promisify() */
fs.writeFile('/tmp/test.js',"console.log('Hello world');", error => {
if(error) return console.log(error);
const getUserInfo = () => new Promise((resolve, reject) => {
process.nextTick(() => resolve({
id: 1,
name: 'Manuel',
surname: 'Romero'
}));
});
const getUserInfo = () => new Promise((resolve, reject) => {
process.nextTick(() => resolve({
id: 1,
name: 'Manuel',
surname: 'Romero'
}));
});
Promise.all([User.findAllUsers(), User.findUserById(<id>)]).then(function(results) {
// results[0] contains the result of the first promise
// results[1] contains the result of the second promise
});
Promise.all([User.findAllUsers(), User.findUserById(<id>)]).then(function(results) {
// results[0] contains the result of the first promise
// results[1] contains the result of the second promise
});
var User = require('route/to/models/User.js');
User.findUserById(<id>).then(function(user) {
user.banned = true;
return User.saveUser(user);
}).then(function() {
return User.removeUserByName('manuel');
var mongoose = require('mongoose');
var schema = new mongoose.Schema({
name: {
type: String,
required: true,
index: {unique: true}
},
banned: {