Skip to content

Instantly share code, notes, and snippets.

Avatar

Luke lukem512

View GitHub Profile
@lukem512
lukem512 / yurt.js
Last active May 15, 2021
Calculator for yurt component dimensions and count. Specify a diameter and a wall height (or use the defaults) and you'll be shown how many poles, and of what lengths, are needed.
View yurt.js
const defaults = {
units: 'ft', // units to use, could be 'ft' or 'm'
diameter: 14, // units
wallHeight: 6, // units, at outer edge
khanaHoleSpacing: 1, // units, spacing between crossing rods
roofAngle: 25, // degrees from horizontal
tonoDiameter: 1, // units
}
function deg2rad(deg) {
@lukem512
lukem512 / lukecaster.html
Created Sep 25, 2020
LukeCaster (a simple JavaScript raycaster)
View lukecaster.html
<html>
<head>
<title>LukeCaster</title>
<script type="text/javascript" src="raycaster.js"></script>
<style type="text/css">
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
View chats-with-messages.html
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Chats</title>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400&display=swap" rel="stylesheet">
<style type="text/css">
:root {
@lukem512
lukem512 / queue.c
Created Jan 24, 2020
Queue (Circular Buffer) ADS
View queue.c
// Luke Mitchell & Max Peglar-Willis, 2020
// <hi@lukemitchell.co>
#include <stdlib.h>
#include <stdbool.h>
#include "queue.h"
// Initialise a new queue of the
// specified size
@lukem512
lukem512 / mix.html
Created Jan 20, 2020
Colour Mixing
View mix.html
<html>
<head>
<title>Colour Swatch Mixing</title>
<style>
.container {
display: flex;
}
.container div {
width: 100px;
@lukem512
lukem512 / colour.js
Created Jan 7, 2020
Generate a random hexadecimal colour code in JavaScript
View colour.js
// Function to generate a 24-bit (non-alpha) colour (color, for US English speakers)
function makeRandomColour() {
const MAX_INT24 = 16777215;
return '#' + Math.round(Math.random() * MAX_INT24).toString(16);
}
@lukem512
lukem512 / swatches.html
Created Dec 18, 2019
Colour Swatches Visualiser
View swatches.html
<!doctype html>
<html>
<head>
<title>Colour Swatches</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #FAFBFC;
}
@lukem512
lukem512 / build.js
Created Jun 13, 2019
Mustache-based translations
View build.js
const fs = require('fs');
var exec = require('child_process').exec;
const DATA = 'data/';
const TEMPLATES = 'templates/';
const OUTPUT = 'build/';
// Retrieve language from args
const args = process.argv.slice(2);
const lang = args[0];
@lukem512
lukem512 / compactBits.js
Created Dec 20, 2017
Bitcoin difficulty target to compact bits conversion
View compactBits.js
var MAX_PRECISION = 28;
function _findExp (n, base, exp = 1) {
var pow = Math.pow(base, exp);
var div = Math.floor(n / pow);
if (exp > MAX_PRECISION) {
return div;
}
return div + _findExp(n, base, exp + 1);
}
@lukem512
lukem512 / combine-ast.js
Created Jun 22, 2017
Combine text elements in AST
View combine-ast.js
let content = node.content;
if (Array.isArray(node.content)) {
// Combine elements of type text
content = node.content.reduce((_content, item) => {
const lastNodeIndex = _content.length - 1;
const lastNode = _content[_content.length - 1];
if (_content.length > 0 && lastNode.type === 'text' && item.type === 'text') {
_content[lastNodeIndex].content = lastNode.content + item.content;
} else {