Skip to content

Instantly share code, notes, and snippets.

@glynnbird
glynnbird / twitter-app3.js
Created November 16, 2016 15:34
Cloudant Envoy Twitter Authentication - Part 3
var path = require('path'),
express = require('express'),
crypto = require('crypto'),
CryptoJS = require("crypto-js"),
uuid = require('uuid'),
cloudant = null,
tokensdb = null,
envoydb = null,
cfenv = require('cfenv'),
appEnv = cfenv.getAppEnv(),
@glynnbird
glynnbird / twitter-app2.js
Last active November 16, 2016 15:36
Cloudant Envoy Twitter authentication - step 2
var path = require('path'),
express = require('express'),
uuid = require('uuid'),
cloudant = null,
cfenv = require('cfenv'),
appEnv = cfenv.getAppEnv(),
appurl = (appEnv.app.application_uris)?'https://'+appEnv.app.application_uris[0]:'http://localhost:'+appEnv.port,
router = express.Router();
var getOrCreateUser = function(profile, callback) {
@glynnbird
glynnbird / twitter-app.js
Created November 16, 2016 15:14
Cloudant Envoy Twitter authentication - stage 1
// setup Envoy to serve out our static files
var opts = {
static: require('path').join(__dirname, './public')
};
// start up the web server
var envoy = require('cloudant-envoy')(opts);
@glynnbird
glynnbird / facebook-app3.js
Last active November 16, 2016 15:10
Cloudant Envoy - Facebook auth - app3.js
var uuid = require('uuid'),
express = require('express'),
CryptoJS = require("crypto-js"),
cloudant = null,
tokensdb = null,
router = express.Router();
var encrypt = function(str, key) {
return CryptoJS.AES.encrypt(str, key).toString();
};
@glynnbird
glynnbird / facebook-app2.js
Last active November 16, 2016 15:10
Cloudant Envoy - Facebook Auth - app2.js
var uuid = require('uuid'),
express = require('express'),
CryptoJS = require("crypto-js"),
router = express.Router();
var encrypt = function(str, key) {
return CryptoJS.AES.encrypt(str, key).toString();
};
var decrypt = function(str, key) {
@glynnbird
glynnbird / facebook-app1.js
Last active November 16, 2016 15:10
Cloudant Envoy - Facebook Auth - app1.js
// setup Envoy to serve out our static files
var opts = {
static: require('path').join(__dirname, './public')
};
// start up the web server
var envoy = require('cloudant-envoy')(opts);
@glynnbird
glynnbird / dash.js
Created September 29, 2016 13:36
Amazon Dash intercept - creating IFTTT action
var dash_button = require('node-dash-button');
var dash = dash_button(MYMACADDRESS, null, null, 'all');
var request = require('request');
dash.on("detected", function () {
var r = {
method: 'post',
url: 'https://maker.ifttt.com/trigger/button_pressed/with/key/MYKEY'
};
request(r, function(e, req, b) {
console.log(b);
@glynnbird
glynnbird / toredis.py
Created September 26, 2016 10:24
Python script to convert simple Redis commands to raw Redis protocol
#!/usr/bin/python
# reads a sequence of REDIS commands from stdin e.g.
# SET mykey "hello world
# into Redis protocol e.g.
# *3
# $3
# SET
# $5
# mykey
@glynnbird
glynnbird / tolatlng.py
Created September 26, 2016 10:23
Python script to convert a Ordnance Survey Code Point Open files to Redis 'GEOADD' commands
#!/usr/bin/python
# based on code from http://www.hannahfry.co.uk/blog/2012/02/01/converting-british-national-grid-to-latitude-and-longitude-ii
#This code converts lat lon (WGS84) to british national grid (OSBG36)
from scipy import *
from itertools import imap
import sys
import csv
// points played by player name
function (doc) {
emit(doc.Player1, 1);
}
// points played by player name - second iteration
function (doc) {
emit(doc.Player1, 1);
emit(doc.Player2, 1);