Skip to content

Instantly share code, notes, and snippets.

View calderonroberto's full-sized avatar

Roberto Calderon calderonroberto

View GitHub Profile
@calderonroberto
calderonroberto / chainofresponsibility.py
Created July 8, 2015 06:28
Chain of responsibility in python (Design Patterns - Gamma, Helm, Johnson, Vlissides)
PRINT_TOPIC = 1
PAPER_ORIENTATION = 2
APPLICATION_TOPIC = 3
NO_HELP_TOPIC = -1
class HelpHandler (object):
def __init__(self, successor=0, topic=NO_HELP_TOPIC):
self._successor = successor
self._topic = topic
def HasHelp(self):
@calderonroberto
calderonroberto / app.py
Last active June 1, 2022 20:06
Flask Redis Example
#!/bin/python
# Dependencies:
# pip install flask
# pip install redis
from flask import Flask
from flask import request
import flask
import redis
@calderonroberto
calderonroberto / app_tests.py
Created June 13, 2015 19:14
Flask Redis Example Tests
import app
import unittest
import json
from random import randint
mocked_value = randint(0,255)
class AppTestCase(unittest.TestCase):
def setUp(self):
self.app = app.app.test_client()
package main
import (
"fmt"
"math"
"time"
)
func fibonacci(n int) int {
a := 0
@calderonroberto
calderonroberto / composing-in.go
Last active November 30, 2015 23:31
Composing in GoLang
package main
import (
"fmt"
)
type User struct {
Name string
}
@calderonroberto
calderonroberto / node-red-sox-examples.json
Created November 24, 2015 00:49
Node RED SOX node examples
[{"id":"d641037b.29bf","type":"websocket-listener","path":"/public/gassentiment","wholemsg":"false"},{"id":"b2e20edd.4d1df","type":"pushbullet-config","name":"PushBullet"},{"id":"496da66e.b69258","type":"wotkit-credentials","nickname":"DataHub","url":"http://hub.urbanopus.net/wotkit/"},{"id":"dd0cde9b.22f32","type":"sox-credentials","nickname":"Sensorizer","bosh":"http://sox.ht.sfc.keio.ac.jp:5280/http-bind/","xmpp":"sox.ht.sfc.keio.ac.jp"},{"id":"57c3f620.a83c08","type":"sox in","name":"","device":"神奈川ガソリン安価ランキング1位","transducer":"price","login":"dd0cde9b.22f32","x":158.0994110107422,"y":84,"z":"e9240feb.16dbf","wires":[["1b9117d3.e46ee8"]]},{"id":"bf10dd9c.40ef2","type":"comment","name":"Sensor Details","info":"http://sensorizer.ht.sfc.keio.ac.jp:8888/status?n=c838934feb10e75a06424c0c963a45ae\n\nCredentials:\n\nsensorizer@sox.ht.sfc.keio.ac.jp\nmiromiro\n","x":80.5,"y":149,"z":"e9240feb.16dbf","wires":[]},{"id":"1b9117d3.e46ee8","type":"function","name":"Extract Price Value","func":"if (msg.payload.name == \
@calderonroberto
calderonroberto / vowelcount-withbinary.js
Created November 20, 2015 06:28
Vowel Count With Binary Search
var withBinarySearch = function (s) {
var vowels = 0;
var vowelArray = ["a","e","i","o","u"]; //already sorted
for (var i = 0; i < s.length-1; i++){
var search = binarySearch(vowelArray,s[i].toLowerCase(),0,4);
if ( search !== -1 ){
vowels++;
}
}
return vowels;
@calderonroberto
calderonroberto / vowelcount-withindex.js
Created November 20, 2015 06:26
Vowel Count with IndexOf
var withIndex = function (s) {
var vowels = 0;
var vowelArray = ["a","e","i","o","u"];
for (var i = 0; i < s.length-1; i++){
if (vowelArray.indexOf(s[i].toLowerCase()) !== -1 ) {
vowels++;
}
}
return vowels;
};
@calderonroberto
calderonroberto / vowelcount-withif.js
Created November 20, 2015 06:25
Vowel count with if
var withIf = function (s) {
var vowels = 0;
for (var i=0; i < s.length-1; i++){
var letter = s[i].toLowerCase();
if (letter === "a" || letter === "e" || letter === "i" || letter === "o" || letter === "u" ){
vowels++;
}
}
return vowels;
};
@calderonroberto
calderonroberto / main.go
Created October 24, 2015 20:54
A very simple Golang Microservice
package main
import (
"net/http"
"log"
"encoding/json"
)
// The Thing Model, mapping the URL.Query() contents
type Thing struct {