Skip to content

Instantly share code, notes, and snippets.

View iainjreid's full-sized avatar
👋

Iain J. Reid iainjreid

👋
View GitHub Profile
#!/bin/sh
exec unshare -c -n -- $@
{
"basics": {
"name": "Iain Reid",
"label": "Software Engineer",
"picture": "https://avatars0.githubusercontent.com/u/10884534",
"website": "https://chaff.land",
"summary": "Information Technology & Services",
"location": {
"city": "London",
"countryCode": "UK"
export const h=(t,m,...c)=>({...m,t,m,c})
export const render=(e,d,t=d.t||(d.t={}),m,r,c)=>
// arrays
[e].flat(1/0).map((e)=>
// components
e.t.call?(e.i=render((render.c=e).t({children:e.c,...e.m},e.s=t.s||{},t=>
render((e.s={...e.s,...t})&&e,d,e)),t.i||d,t?.i||{}),e):(
// create notes
e.d=t.d||(e.t?document.createElement(e.t):new Text(e.m)),
// diff props
@iainjreid
iainjreid / javascript-proxy-default-properties.js
Created February 17, 2020 21:43
Default properties using a JavaScript Proxy
const dog = defaultProperties({
breed: 'Dachshund',
name: 'Sam',
age: 3
}, 'empty');
dog.name // 'Sam'
dog.foodBowl // 'Empty'
@iainjreid
iainjreid / javascript-proxy-protected-properties.js
Created February 16, 2020 23:24
Protecting properties using a JavaScript Proxy
const dog = {
breed: 'Labrador',
name: 'Jed',
age: 7
};
const dogCopy = protectProperties(dog);
dog.breed = 'Poodle'; // Success - We've now got a Poodle
@iainjreid
iainjreid / javascript-proxy-property-validation.js
Last active February 17, 2020 12:55
Property validation using a JavaScript Proxy
const shape = new Proxy({}, {
set: (obj, prop, value) => {
if (prop === 'sides') {
if (!(value > 0)) {
throw Error('Property "sides" must be greater than zero');
}
}
// Set the value
obj[prop] = value;
@iainjreid
iainjreid / index.js
Last active September 30, 2019 07:37
A very simple TCP echo server, written in Node.js
const net = require('net')
net.createServer(socket => {
socket.on('data', function(data){
console.log('Echoing: %s', data.toString())
socket.write(data.toString())
})
}).listen(8001)
@iainjreid
iainjreid / package-json.d.ts
Last active February 13, 2020 20:28
A Typescript type definition for NPM package files
export interface IPackageJSON extends Object {
readonly name: string;
readonly version?: string;
readonly description?: string;
readonly keywords?: string[];
@iainjreid
iainjreid / bower-json.d.ts
Last active January 5, 2017 15:58
A Typescript type definition for Bower package files
export interface IBowerJSON extends Object {
/**
* The name of the package as stored in the registry
*/
readonly name: string;
/**
* A description of the package limited to 140 characters
*/
@iainjreid
iainjreid / Node.js static file server
Last active August 2, 2018 19:28
Serve static files, HTML, CSS, JS, etc, using Node.js
var fs = require('fs'),
http = require('http');
http.createServer(function (req, res) {
console.log('Incoming request');
fs.readFile('.' + req.url, function (err, file) {
if (err) {
res.writeHead(404, {
'Content-Type': 'text/plain'
});