Skip to content

Instantly share code, notes, and snippets.

@mveinot
mveinot / gist:5670452
Created May 29, 2013 13:59
Example I2C code on Arduino
// This is the I2C Master
#include <Wire.h>
#define LED_PIN 13
byte x = 0;
void setup()
{
Wire.begin(); // Start I2C Bus as Master
<?php
$address = isset($_GET['address'])?$_GET['address']:null;
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
function get_w1_address($address)
{
$bus_addr = substr($address,0,2).'-';
function highlightSearchTerms(sword) {
$$('body').map(Element.extend).first().descendants().each(function (el) {
if (el.nodeType == Node.ELEMENT_NODE && el.tagName != 'TEXTAREA' && el.tagName != 'INPUT' && el.tagName != 'SCRIPT') {
$A(el.childNodes).each(function (onlyChild) {
var pos = onlyChild.textContent.indexOf(sword);
if (onlyChild.nodeType == Node.TEXT_NODE && pos >= 0) {
//console.log(onlyChild);
var spannode = document.createElement('span');
spannode.className = 'highlight';
var middlebit = onlyChild.splitText(pos);
@mveinot
mveinot / gist:c194d9cbc366144ed62d
Last active August 29, 2015 14:23
Look for a specified USB device
#!/bin/bash
# Specify the product ID of your device
DEVICE="0x2838"
# the command to list USB devices
USB_DEVICE_CMD="system_profiler SPUSBDataType"
# get the list and filter for the device we're looking for
DEVICE_PRESENT=`$USB_DEVICE_CMD | grep $DEVICE | cut -f2 -d':'`
@mveinot
mveinot / iTunesLCD.cpp
Created November 28, 2015 14:28
Monitor serial for commands
#include <LiquidCrystal.h>
// tell the library which pins the LCD is connected on
LiquidCrystal lcd(12,11,10,5,4,3,2);
void setup()
{
// initialize the serial port to 9600 baud (it's fast enough)
Serial.begin(9600);
// initialize the lcd to 16 columns, 2 rows
@mveinot
mveinot / sendLCDcommand.pl
Created November 28, 2015 14:31
Send commands to a connected LCD over serial
#!/usr/bin/perl -w
use strict;
use warnings;
chomp(my $status = `osascript -e 'tell application "iTunes" to player state as string'`);
if ($status eq 'playing')
{
chomp(my $artist = `osascript -e 'tell application "iTunes" to artist of current track as string'`);
/************************
Version history
0.99.14 - Jan 12/2016
Migrate to MQTT for notifications
0.99.13 - Jan 7/2016
Add /temperature route to just return text/plain current temperature
0.99.12 - Jan 2/2016
Add DS18B20 for temperature sensing and reporting
Use SPIFFS filesystem for hosting web assets
0.99.11 - Dec 25/2015
// ESP8266 with 20x4 i2c LCD
// Compatible with the Arduino IDE 1.6.4
// Library https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
// Bavensky :3
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#!/usr/bin/python3
import untangle
doc = untangle.parse('/home/gpeverill/bryden.xml')
# use python's handy 'for item in list' syntax to traverse the list of Assets
for asset in doc.root.Dealership.Assets.Asset:
# save the VIN cdata value to a variable and print it
@mveinot
mveinot / scrape.py
Last active November 30, 2016 17:02
#!/usr/bin/python3
import urllib.request
import lxml.html
import untangle
import sys
def rchop(the_string, sub_str):
if (the_string.endswith(sub_str)):
return the_string[:-len(sub_str)]