Skip to content

Instantly share code, notes, and snippets.

View alexellis's full-sized avatar
📖
Check out my eBook on Go

Alex Ellis alexellis

📖
Check out my eBook on Go
View GitHub Profile
@alexellis
alexellis / gist:1ebca0b448fd623b672d
Created January 16, 2015 14:43
Laser/torch trip wire for Arduino. Uses RCTime equation and capacitor/LDR.
int sensorPin = 7; // 220 or 1k resistor connected to this pin
long threshold = 200;
long ambientReading;
long ambientReadingCount;
bool tripEnabled = false;
int LED_PIN = 3;
int BUZZER_PIN = 4;
int ambientReadingsToTake = 10;
@alexellis
alexellis / esvlookup.js
Created September 14, 2015 15:49
Sample in node.js for fetching passage from ESV's restful API in plain-text format
// Author: Alex Ellis 2015
// Sample in node.js for fetching passage from ESV's restful API in plain-text format.
//
// 1) Save this file as esvlookup.js
//
// 2) Install module for making HTTP requests
// npm install request
// 3) Run the program and fetch the passage about being 'born-again'
// node lookup.js John 3:1-3
@alexellis
alexellis / motorbyte.c
Created September 17, 2015 08:13
Chinese 60A motor controller tester
#define enablePin 2
#define IN1_L 3
#define IN3_R 6
#define IN2_L 5
#define IN4_R 9
int engineSpeed;
const int BRAKE=0;
const int FORWARDS=1;
@alexellis
alexellis / plantwater.pde
Created September 21, 2015 18:26
Plant watering automation
#define MOTOR_PIN 3
#define SENSOR_VCC 9
#define SENSOR_MOISTURE A2
#define MOISTURE_THRESHOLD 700
#define SENSOR_WARMUP 1200
#define SAMPLE_DELAY 8000
void setup() {
pinMode(SENSOR_VCC, OUTPUT);
pinMode(MOTOR_PIN, OUTPUT);
@alexellis
alexellis / noderedisfail.js
Created January 7, 2016 13:07
node-redis-fail
var redis = require ('node-redis');
var updateCounter = function(done) {
var client = redis.createClient("6379",function (err) {
if(err) {
return console.error(err);
}
client.incr("hit_counter", function(ierr) {
if(ierr) {
return console.error(ierr);
@alexellis
alexellis / RaspberryPiFinder.js
Last active April 8, 2016 22:26
RaspberryPiFinderSolution
var request = require('request');
var async = require('async');
var found = [];
async.until(function() {
return false; // infinite async-loop, insert counter check here.
}, function(cb) {
request.head("https://www.raspberrypi.org/blog/the-little-computer-that-could/",
function(err, res, body) {
@alexellis
alexellis / consul.lua
Created May 15, 2016 08:16 — forked from gmr/consul.lua
Dynamic Nginx upstream nodes using Consul
module("resty.consul", package.seeall)
_VERSION = '0.1.0'
function service_nodes(service)
local http = require "resty.http"
local json = require "cjson"
local hc = http:new()
local upstream = ""
# This was broken until I changed GPIO.BCM to GPIO.BOARD
import RPi.GPIO as GPIO
import time
import os
# Define PiLITEr to GPIO mapping
leds = [7,11,13,12,15,16,18,22]
GPIO.setmode(GPIO.BOARD)
@alexellis
alexellis / twitter2slackbot.js
Created May 31, 2016 20:43
Twitter2SlackBot - watches Hashtags and pushes them into your selected slack channel.
// Needs a config.json file with slack and twitter keys/secrets/tokens.
// Sample config at end of file.
"use strict"
let util = require('util')
var Twitter = require('twitter');
let config = require('./config.json');
let async = require('async');
@alexellis
alexellis / twitter2slackbot.js
Last active May 31, 2016 21:09
Twitter2SlackBot - watches Hashtags and pushes them into your selected slack channel.
"use strict"
// Needs a config.json file with slack and twitter keys/secrets/tokens.
// Sample config at end of file.
let util = require('util')
var Twitter = require('twitter');
let config = require('./config.json');
let async = require('async');
let fs = require('fs');