Skip to content

Instantly share code, notes, and snippets.

import { useEffect, useState } from 'react';
const ClientSideApp = ({ children }) => {
// Make Next OK with fully client-side rendering, as described in https://colinhacks.com/essays/building-a-spa-with-nextjs
const [render, setRender] = useState(false);
useEffect(() => setRender(true), []);
return render ? children : null;
};
function App ({ Component, pageProps }) {
function getURLParam(param) {
if (window.location.search.indexOf(param + '=') === -1) {
return undefined;
}
return window.location.search.split(param + '=')[1].split(/&|#/)[0];
}
// Returns 'yesterday', 'today', 'tomorrow', or else the full day name
getDayName(mo) {
const daysDifferenceToToday = mo.startOf('day').diff(moment().startOf('day'), 'days');
const differenceMask = {
'-1': 'Yesterday',
0: 'Today',
1: 'Tomorrow'
};

'Why I support humans.txt and you should too.'

<nostalgia> In 2001 I landed my first web development job on the strength of being cheap and enthusiastic. Back then "web developer" wasn't a universal term for what we do so I think my job title was simply "Programmer" (later: "Internet Programmer" and finally progressing to the dizzy heights of "Senior Database Programmer", all of which conjure images of reel-to-reel tapes and brown computers the size of bungalows.).

When I was hired, I already had a basic knowledge of HTML tables and I knew how to use JavaScript for image rollovers. CSS was an experimental feature in some obscure browsers used by geeks, like Mozilla Firebird (yes, bird) and the shareware browser Opera.

<source> One of the best things about learning web development is that you can do it on any desktop computer that has a browser and a text editor.

@user24
user24 / accessproxy.js
Last active June 4, 2018 15:49
Proxy connections, opening up Access-control-allow-origin
/*jslint node:true*/
// Usage curl localhost:8080/http://example.com
// - proxies the request, adding Access-control-allow-origin: * and stripping Origin and Referer headers and fixing Host
"use strict";
var request = require("request"),
http = require("http"),
url = require("url");
http.createServer(function proxy(req, res) {
var searchArray = [1,2,3];
var targetValue = 2;
// Not supported in MSIE
searchArray.find(function (val) {
return val === targetValue;
});
// Supported in MSIE
searchArray.filter(function (val) {
Cover cubed beef in flour, pepper & thyme.
Fry with oil & soon add a shot of lightly peated whisky, e.g. Jura Superstition.
Add rough chopped onion, thinly sliced carrots, 1 large crushed garlic clove and quartered button mushrooms.
Fry till onions soft.
Add about 250ml of beef stock with extra thyme (I used a whole cube of Kallo Beef stock)
Simmer to reduce.
Add about 300ml of full bodied red wine, e.g. Merlot, and some more whisky (this time I used Penderyn as it's lighter)
Simmer to reduce.
Serve with steamed veg and bread, dumplings, or spring onion mash, or use as a pie filling.
define(['require', 'dependency1', 'dependency2'], function (require, dependency1, dependency2) {
return function () {};
});
@user24
user24 / toggle.js
Created January 7, 2014 21:22
Toggle Comments
/**/
someCode();
goesHere();
lotsOfCode();
/**/
// With removal/addition of just one char we can toggle commenting of the whole block:
/**
someCode();
@user24
user24 / variable-names.js
Last active December 14, 2015 15:58
Code Clarity by hoisting logic into nicely named variables
// Succinct, does not create strictly unnecessary variables
// but not easy to read
if((a.notes && a.notes.trim() != "") && (b.notes && b.notes.trim() != "")) {
skip = true;
console.log('too many notes - skipping');
}
// Verbose, creates two vars which are not really needed
// but it's instantly clear what the 'if' is doing
var aHasNotes = (a.notes && a.notes.trim() != "");