Skip to content

Instantly share code, notes, and snippets.

var Promise = require('bluebird');
function Micro (id) {
this.id = id;
}
Micro.prototype.connect = function () {
return new Promise(function (fulfill, reject) {
setTimeout(function() {
if (Math.random() > 0.5)
BluebirdMikrotik.prototype.connect = function () {
var p = new Promise.defer();
//console.log('intentando conexion')
this.api.connect(function(c) {
console.log(c)
this.con=c
console.log('.')
console.log(this.con)
p.resolve()
}.bind(this)); //*********************** BIND
var Promise = require('bluebird')
var Api = require('mikronode');
var colors = require('colors')
var con, api
var BluebirdMikrotik = function(a,debug){
console.log(a)
this.api = new Api(a.host,a.user,a.password);
}
@fortruce
fortruce / realtime-graph.py
Created August 30, 2014 16:30
This is a simple example of how to use Matplotlib and Python to create a realtime graph of incoming data (simulated in the example).
import matplotlib.pyplot as plt
import matplotlib.animation as anim
from collections import deque
import random
MAX_X = 100 #width of graph
MAX_Y = 1000 #height of graph
# intialize line to horizontal line on 0
line = deque([0.0]*MAX_X, maxlen=MAX_X)
@fortruce
fortruce / gist:b040885fb49a3a643623
Created May 23, 2014 17:32
Clojure Removing Dependencies on Global State
;; This is a weird LightTable REPL session trying to understand how to actually use the concepts outlined
;; in http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded and the related talk he gave at
;; Clojure West.
;; The following code does NOT make sense when run in order as I was evaluating things on the fly with LightTable.
(defn system []
{:db {:conn nil
:collection "collection"}})
(defn start [system]
@fortruce
fortruce / pluralize.clj
Last active August 29, 2015 13:55
Naive pluralization helper function.
(defn pluralize
"Takes an integer and a string and returns a string of '%d %s' where %s is pluralized based on %d.
Assumes x >= 1 and s is singular."
([x s] (pluralize x s nil))
([x s ss]
(format "%d %s" x
(if (= 1 x) s
(or ss (condp re-matches s
#".*(x|[^aeiou]o|ch|s)" (str s "es")
#".*[^aeiou]y" (str (apply str (drop-last s)) "ies")