This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('api_spi.js'); | |
load('api_timer.js'); | |
load('api_math.js'); | |
let spi = SPI.get(); | |
let light = function(ar) { | |
let frame = '\x00\x00\x00\x00'; | |
for (let i = 0; i < ar.length; i++) { | |
print(typeof(ar[i]), ar[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////// old | |
function old1() { | |
}; | |
function old2() { | |
old1(); | |
} | |
old2(); | |
////////// new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('api_dht.js'); | |
load('api_mqtt.js'); | |
load('api_timer.js'); | |
Timer.set(1000, true, function() { | |
let data = { temperature: DHT.getTemp(), humidity: DHT.getHumidity() }; | |
MQTT.pub('dev/1234', JSON.stringify(data), 1); | |
}, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('api_aws.js'); | |
load('api_gpio.js'); | |
load('api_mqtt.js'); | |
let state = { on: false, counter: 0 }; // device state: shadow metadata | |
GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() { | |
AWS.Shadow.update(0, {desired: {on: state.on, counter: state.counter + 1}}); | |
}, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compiling and starting server: | |
// $ cc ian1.c mongoose/mongoose.c frozen/frozen.c -I mongoose/ -I frozen -o /tmp/a | |
// $ /tmp/a | |
// Starting web server on port 8001 | |
// | |
// Running the client: | |
// $ curl -d '' 127.0.0.1:8001 | |
// {"error": {"code": -1, "message": "Expected a, b"}} | |
// $ curl -d '{"b": 34, "a": 12}' 127.0.0.1:8001 | |
// {"result": 46} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var reconnect = function() { | |
var url = 'ws://' + location.host + '/ws'; | |
ws = new WebSocket(url); | |
ws.onopen = function(ev) { console.log(ev); }; | |
ws.onclose = function(ev) { console.log(ev); setTimeout(reconnect, 1000); }; | |
ws.onmessage = function(ev) { console.log('message', ev); }; | |
ws.onerror = function(ev) { console.log('error', ev); ws.close(); }; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "web_server", | |
"description": "web server skeleton", | |
"version": "1.0.0", | |
"private": false, | |
"dependencies": { | |
"express": "3.x", | |
"sqlite3": "*", | |
"minimist": "*", | |
"supervisor": "*", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ cc -W -Wall ~/tmp/mess.c && ./a.out | |
// {"a": 9, "c": "i am bar", "d": [{"a": 3, "b": null}, {"a": 7, "b": "oops"}]} | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <string.h> | |
#include "mess.h" | |
#define STRUCT_NAME foo | |
#define STRUCT_FIELDS ATTR(int, a) ATTR(char *, b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#define LISTENING_PORT 8000 | |
static void serve_new_connection(FILE *fp) { | |
char method[10], uri[100], protocol[20]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>GitHub Stars</title> | |
</head> | |
<body> | |
hi | |
</body> | |
</html> |