Skip to content

Instantly share code, notes, and snippets.

View urish's full-sized avatar

Uri Shaked urish

View GitHub Profile
@urish
urish / googleForms.js
Created January 21, 2016 12:28
Angular service to post reponses to a google form
function googleFormsService ($q, $rootScope, jQuery) {
angular.extend(this, {
/**
* Sends a response using Google Forms AJAX API (informal)
* @param {String} formKey The key of the form, e.g. 15QFO2VE44-9gAwcJeTPPWvxAX7v_1Ye9qmjdX2VzLBw
* @param {Object} values A list of key-value pairs to send as the form data, e.g. {'entry.6939333': 'John', 'entry.7399349': Due}
* @returns {*} Promise that will be resolved after the form request has been submitted
*/
sendResponse(formKey, values) {
var deferred = $q.defer();
@urish
urish / install.sh
Created July 17, 2016 08:45
Installing airfoilspeakers on nextthingco CHIP
#! /bin/sh
wget http://rogueamoeba.com/airfoil/download/AirfoilSpeakersLinux.all.deb
wget http://rogueamoeba.com/airfoil/download/AirfoilSpeakersRaspberryPi.tgz
sudo dpkg -i AirfoilSpeakersLinux.all.deb
sudo apt-get install -f
tar zxf AirfoilSpeakersRaspberryPi.tgz
sudo cp -p ./airfoilspeakers/lib/*ARM.so /usr/lib/airfoilspeakers
airfoilspeakers
@urish
urish / lightsnake.ino
Last active January 7, 2017 15:06
APA102 Light snake (Arduino)
#include <FastGPIO.h>
#define APA102_USE_FAST_GPIO
#include <APA102.h>
APA102<11, 12> ledStrip;
const uint16_t ledCount = 144;
rgb_color pixels[ledCount];
void setup() {
@urish
urish / demo.js
Created October 9, 2011 18:56
Titanium URL download
var ZLSound = require('com.salsarhythmsoftware.zlsound');
function createUrlSound(url, localFilename) {
var sound = nil;
var autoPlay = false;
var request = Titanium.Network.createHTTPClient();
var soundFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, localFilename);
if (soundFile.exists()) {
return ZLSound.createSample({media: soundFile.nativePath});
}
@urish
urish / ng-beacon-bulb.js
Last active March 25, 2017 00:41
ng-beacon controlling a Magic Blue smart bulb
function startLoop(char) {
console.log('Connected !');
setInterval(function() {
var t = ngbeacon.temperature();
console.log(t);
var r = t > 22 ? 0xff : 0,
g = 0,
b = t > 22 ? 0 : 0xff;
char.writeValue(new Uint8Array([0x56, r, g, b, 0, 0xf0, 0xaa]));
}, 1000);
function updateValues() {
var temperature = new Uint16Array([ngbeacon.humidity() * 100]);
var humidity = new Uint16Array([ngbeacon.humidity() * 100]);
NRF.updateServices({
0x181A: {
0x2A6E: { value: temperature.buffer, notify: true },
0x2A6F: { value: humidity.buffer, notify: true }
}
});
}
@urish
urish / ng-beacon-bulb-rssi.js
Created April 24, 2017 11:01
NG Beacon controlling a Magic Blue bulb based on distance
var bulbDevice = null;
var bulbChar = null;
function setColor(r, g, b) {
try {
bulbChar.writeValue(new Uint8Array([0x56, r, g, b, 0, 0xf0, 0xaa]));
} catch (e) {
}
}
@urish
urish / sneeze-light-control.js
Last active May 3, 2017 16:52
Control Smart Bluetooth Bulb with sound
const SNEEZE_THRESHOLD = 0.01;
const SNEEZE_TIMEOUT = 1000; /* ms */
async function sneezeControl() {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const audioCtx = new AudioContext();
const source = audioCtx.createMediaStreamSource(stream);
const analyser = audioCtx.createAnalyser();
const dataArray = new Float32Array(analyser.fftSize);
let lastEvent = new Date().getTime();
// Read the data through Web Bluetooth + visualize demo: https://plnkr.co/edit/96usNYVyKIo3s6pQB1Cu?p=preview
var mpu = require("MPU6050").connect(I2C1);
const BLE_UART_UUID = [0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,0xa3,0xb5,0x01,0x00,0x40,0x6e];
const EIR = {
CompleteListOf16BitServiceUuids: 0x3,
IncompleteListOf128BitServiceUuids: 0x6,
CompleteLocalName: 0x9,
@urish
urish / async-iteration-firefox.js
Created July 17, 2017 14:41
Async Iteration Example (Firefox Nightly)
// noprotect
async function sunsetTime(date) {
const resp = await fetch(`https://api.sunrise-sunset.org/json?lat=32.095&lng=34.847&formatted=0&date=${date}`)
const result = await resp.json();
return new Date(result.results.sunset);
}
async function *getSunsets() {
for (let day = 1; day <= 31; day++) {