Skip to content

Instantly share code, notes, and snippets.

View mikemaccana's full-sized avatar

Mike MacCana mikemaccana

View GitHub Profile
@mikemaccana
mikemaccana / manipulating-arrays.js
Created February 26, 2020 17:47 — forked from DMeechan/manipulating-arrays.js
Reading, manipulating, and writing arrays in JavaScript
// runTests();
const fs = require("fs");
const fileOne = "../exports/someA.csv";
const fileTwo = "../exports/someB.csv";
const fileThree = "../exports/someC.csv";
const outputFile = "../exports/someOut.csv";
const arrayOne = readFile(fileOne);
// Stolen from https://github.com/rauschma/op_overload and ported to ES6
const log = console.log.bind(console)
var operands = []
class Point {
constructor(x, y) {
if (arguments.length === 0) {
x = 0
@mikemaccana
mikemaccana / gist:d9372cbd1acddbd4ff1ac1d015882168
Created October 4, 2019 13:13
Number methods (5..days etc) in JS
// Stolen from https://github.com/mikemaccana/agave/blob/master/index.js
const MILLISECONDS_IN_SECOND = 1000,
SECONDS_IN_MINUTE = 60,
MINUTES_IN_HOUR = 60,
HOURS_IN_DAY = 24,
DAYS_IN_WEEK = 7,
DAYS_IN_MONTH = 30,
DAYS_IN_YEAR = 365
// Normally you'd name functions with a verb, but since
@mikemaccana
mikemaccana / runme.js
Created April 25, 2019 10:12
Unfuck webchat.freenode.net
var styles = `
.qwebirc-qui .ircwindow div {
font-family: medium-content-serif-font,Georgia,Cambria,"Times New Roman",Times,serif;
margin: 26px auto 0 auto;
max-width: 650px;
}
.qwebirc-qui .lines {
font-size: 18px;
line-height: 1.58;
@mikemaccana
mikemaccana / instructions.md
Created September 11, 2017 17:24
Moving to yarn for modules everywhere / monorepo pattern

Moving to yarn for modules everywhere / monorepo pattern

npm/npm#17929 still occurs in npm 5.4.1 - private packages on the local disk are deleted whenever npm is used.

If npm fixes this in future great, but in the meantime, for others having the issue, if you're using monorepo / modules everywhere:

  • Install yarn and run yarn config set workspaces-experimental true
  • Move your private packages to /packages
  • Add a yarn workspace to your package.json with:
# See https://circleci.com/docs/2.0/configuration-reference (badly written)
# And https://circleci.com/docs/2.0/configuration-reference/#full-example (better)
version: 2
jobs:
build:
docker:
# Circle does not currently have a node 8 image
# https://circleci.com/docs/2.0/circleci-images/#nodejs
- image: circleci/node:latest
@mikemaccana
mikemaccana / gist:badf6c16f203e05c02b42f93cb740b46
Last active June 28, 2017 13:53
Awful Microsoft crypto article - 'use DES' and other bad ideas. Now 404d.

Do not follow this advice, it is awful.

This is an archive of https://support.microsoft.com/en-us/help/307010

How to encrypt and decrypt a file by using Visual C#

For a Microsoft Visual Basic .NET version of this article, see 301070 .

This article refers to the following Microsoft .NET Framework Class Library namespaces: System.IO

@mikemaccana
mikemaccana / promise_monad.md
Last active June 21, 2017 11:02 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation for the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed to. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing a

@mikemaccana
mikemaccana / promise_monad.md
Created June 21, 2017 10:59 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation for the Promise monad

async/await is just the do-notation of the Promise monad

Mike MacCana just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I fully heartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but they failed too. Finally, async/await is here and, combined with Promises, they solve the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing a function that r

@mikemaccana
mikemaccana / gist:6f3b9c004c0e5ed55d9f
Created January 28, 2016 17:49
Node 4 LTS on CircleCI
machine:
node:
version: 4.2.2
# From for occasional ELIFECYCLE errors compiling microtime
# https://discuss.circleci.com/t/using-node-js-4-0-on-circleci/26
# Modified to use 'pre' rather than 'override' so 'npm install' runs
# See https://circleci.com/docs/configuration
dependencies:
pre: