Skip to content

Instantly share code, notes, and snippets.

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.

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.
$('#calendar .barIcons > .barIcon').each(function (i, icon) {
var left;
icon = $(icon);
left = parseInt(icon.position().left, 10);
alert(left); // increases each time
return; // Comment this and now the alert is zero each time.
icon.css({
"position": "absolute"
});
// It would be very simple to write this function to sort-of mimic let;
lett({
'blockScopeVar': 4
}, function (blockScopeVar) {
//blockScopeVar === 4 // true
});
// Then when you want to change the code to actually use let, it's fairly easy;
// just write your let declarations and rip out the callback's innards;
// Hide all miniapps.
// for promise().done() explanation, see http://api.jquery.com/promise/#example-1
// tldr; if you put a .complete() callback in an animation which matches > 1 element
// the callback will be called once per matching element
// We don't want that, we want the callback to run once all animations are complete.
$('.miniapp').slideUp("fast").promise().done(function runMeWhenAllSlideupsAreComplete() {
// This is called whenever any data changes that affects the weekly totals
// What we do in that case is modify our local representation of the weekly data and emit an event
// This way, modules can listen for that event and respond to it without having to wait for
// the server to generate new weekly totals
// document.body.scrollTop = 1; // uncomment this line and it works every time.
console.log(daysTop); // 15141
console.log($(document).height()); // 54005
document.body.scrollTop = daysTop;
console.log(document.body.scrollTop); // 0, sometimes, in chrome (and the page doesn't move to 15141)....
/*
if I attach the above code to a click handler, then when the bug occurs, it occurs on
every click until I manually scroll the page, then it starts working.