Skip to content

Instantly share code, notes, and snippets.

View thisisjofrank's full-sized avatar

Jo Franchetti thisisjofrank

View GitHub Profile
@thisisjofrank
thisisjofrank / example.html
Last active October 18, 2016 13:12
Codebar Media Queries Tutorial
<!DOCTYPE html>
<html>
<head>
<title>Grace Hopper</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="header">
@thisisjofrank
thisisjofrank / script.js
Last active April 16, 2020 22:45
startGame function
async function startGame() {
dataSource = new AblyTrainArrivalsClient()
game = new Game();
ui = new GameUi(game);
game.start({
onGameStart: async () => await dataSource.listenForEvents("940GZZLUKSX", msg => game.registerEvent(game, msg)),
onGameEnd: () => dataSource.stopListening()
});
ui.startRendering(game);
@thisisjofrank
thisisjofrank / problem.js
Created April 20, 2020 08:44
An example of a Problem class
class MyRandomProblem extends Problem {
constructor(x, y) {
super(x, y);
}
tick(platform) {
// Do something
this.ticks++;
}
onCompletion(platform) {
@thisisjofrank
thisisjofrank / neopixel.ino
Last active May 20, 2020 10:40
Set neopixel LEDs to a single colour using an adafruit feather huzzah
#include <Adafruit_NeoPixel.h> // Include the Neopixel library
#ifdef __AVR__
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 4
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 256 // Popular NeoPixel ring size
@thisisjofrank
thisisjofrank / script.js
Last active May 20, 2020 15:03
Connecting to a data channel with Ably
async function connect() {
// set up an instance of the Ably realtime library
const ably = new Ably.Realtime.Promise({ authUrl: '/api/createTokenRequest' });
// create a channel called "tshirt"
const channelId = "tshirt";
//connect to the tshirt channel
const channel = await ably.channels.get(channelId);
await channel.attach();
@thisisjofrank
thisisjofrank / script.js
Last active May 21, 2020 10:01
Publish an event to an Ably channel
// get each of the squares in the svg
const squares = document.getElementsByClassName('square');
// create an onClick function
const onClick = (e) => colorAndPublish(e, channel);
// add an eventlistener for a click event to each square
for (let square of squares) {
square.addEventListener("click", onClick, false);
}
// Include the required headers
#include <ESP8266WiFi.h>
#include "MqttConnection.h"
#include "DataStructures.h"
#include <WiFiClientSecure.h>
#include <MQTT.h>
// create an instance of WifiClientSecure, and call it espClient
WiFiClientSecure espClient;
@thisisjofrank
thisisjofrank / lights.cpp
Created May 21, 2020 18:05
process the message once received
// Example = 001#aa00ff
// Split message at '#' into pixel_number and hex_colour
const auto pixel_end = framedata.indexOf('#', 0);
const auto pixel_number_str = framedata.substring(0, pixel_end);
const auto hex_colour_str = framedata.substring(pixel_end + 1);
auto pixel_number = pixel_number_str.toInt();
char hex_code[7];
int r, g, b = 0;
@thisisjofrank
thisisjofrank / snake.cpp
Created May 22, 2020 09:48
reverse every other line of the array
// calculate x and y positioning of the pixel selected
auto y = pixel / 16;
auto shouldSnake = y % 2 == 0;
auto prevPixels = y * 16;
auto regularX = (pixel % 16);
auto snakeX = (15 - regularX);
auto x = shouldSnake ? snakeX : regularX;
@thisisjofrank
thisisjofrank / ably.html
Created July 6, 2020 11:28
ably-pubnub-demo
<!DOCTYPE html>
<html>
<head>
<title>PubNub JavaScript SDK QuickStart</title>
</head>
<body>
<div>
<strong>Earth:</strong> <input id="update-text" type="input" placeholder="enter update for Earth here"/>
<input id="publish-button" type="submit" value="Submit Update to The Guide"/>