Skip to content

Instantly share code, notes, and snippets.

View PaulKinlan's full-sized avatar

Paul Kinlan PaulKinlan

View GitHub Profile
@PaulKinlan
PaulKinlan / screenrecord.js
Created December 16, 2016 07:06
ScreenRecord.js
(function() {
// Download locally
function download(blob) {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'test.webm';
document.body.appendChild(a);
a.click();
@PaulKinlan
PaulKinlan / canvasrecord.js
Last active August 9, 2022 11:55
Screen recorder in JS
(function() {
let canvas = document.querySelector('canvas');
// Optional frames per second argument.
let stream = canvas.captureStream(25);
var options = {mimeType: 'video/webm; codecs=vp9'};
let recorder = new MediaRecorder(stream, options);
let blobs = [];
function download(blob) {
var url = window.URL.createObjectURL(blob);
@PaulKinlan
PaulKinlan / waitForElement.js
Last active July 19, 2022 22:32
waitForElement.js
function waitForElement(selector) {
return new Promise(function(resolve, reject) {
var element = document.querySelector(selector);
if(element) {
resolve(element);
return;
}
var observer = new MutationObserver(function(mutations) {
@PaulKinlan
PaulKinlan / monitorEvents.js
Created October 14, 2016 07:38
monitorEvents.js
function monitorEvents(element) {
var log = function(e) { console.log(e);};
var events = [];
for(var i in element) {
if(i.startsWith("on")) events.push(i.substr(2));
}
events.forEach(function(eventName) {
element.addEventListener(eventName, log);
});
@PaulKinlan
PaulKinlan / main.py
Created October 11, 2016 21:56
BBC Micro:bit Arkanoid clone
from microbit import *
# quickly create a level of two rows, with pixels set to 0 hits and 1 hits
blocks = [[1 - i for j in range(5) ] for i in range(2)]
ball = [2, 3]
ball_direction = [1,-1]
paddle = [2, 4]
previous_game_time = running_time()
ball_timing = running_time()
game_time = running_time()
@PaulKinlan
PaulKinlan / manifest-polyfill.html
Last active February 27, 2018 17:49
Web App Manifest Polyfill for iOS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="manifest" href="https://jsbin-user-assets.s3.amazonaws.com/kinlan/manifest.json">
<title>iOS Manifest Polyfill</title>
</head>
<body>
@PaulKinlan
PaulKinlan / add-to-homescreen-test.html
Last active September 24, 2020 20:37
iOS Add to Homescreen => simulate web app manifest
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Add to Homescreen</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Test name 2">
@PaulKinlan
PaulKinlan / RGBtoHSL.js
Last active June 1, 2016 10:24
Coverts RGB values to HSL
const RGBToHSL = (r,g,b) => {
// Algo http://www.rapidtables.com/convert/color/rgb-to-hsl.htm
const [r1,g1,b1] = [r/255, g/255, b/255];
const [cmax, cmin] = [Math.max(r1,g1,b1), Math.min(r1,g1,b1)];
const d = (cmax - cmin);
const L = (cmax + cmin) / 2;
const S = d == 0 ? 0 : (d / ( 1 - Math.abs(2*L-1)));
const H = d == 0 ? 0 :
@PaulKinlan
PaulKinlan / HSLToRGB.js
Last active June 1, 2016 10:24
Converts an HSL value to RGB
const HSLToRBG = (H, S, L) => {
// algo http://www.rapidtables.com/convert/color/hsl-to-rgb.htm
const C = (1 - Math.abs(2*L - 1)) * S;
const X = C * (1 - Math.abs(((H / 60) % 2)-1));
const m = L - C/2;
const [r1, g1, b1] = H >= 0 && H < 60 ? [C, X, 0] :
H >= 60 && H < 120 ? [X, C, 0] :
H >= 120 && H < 180 ? [0, C, X] :
H >= 180 && H < 240 ? [0, X, C] :
@PaulKinlan
PaulKinlan / bookmark.js
Last active June 27, 2016 05:03
Progressive Web App Checklist
(function() {
var ManifestParser = (function() {
'use strict';
var _jsonInput = {};
var _manifest = {};
var _logs = [];
var _tips = [];
var _success = true;