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 / GetNasaEarth.js
Last active July 23, 2020 16:37
NASA Earth Imagery, download tool - node.js
// * Download a tile/thumbnail from the LandSat 8 dataset.
// Create directory called 'images'
// npm install request path async
// node GetNasaEarth lat lon
// * How program works
// First find all passes by date of the satellite, then request a thumbnail from the API
// Follow API through and download the images in batches of 5.
// Timing is to off-set throttling on the data-API.
@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 / HashTableInJavaScript.js
Created March 8, 2016 20:15
HashTableInJavaScript
function AHashtable(size) {
this.table = this.init_table(size);
}
AHashtable.prototype.set = function(key, value) {
var self = this;
var index = self.jenkins_hash(key, self.table.length);
self.table[index] = value;
};
@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)