Skip to content

Instantly share code, notes, and snippets.

View leggsimon's full-sized avatar
🙃

Simon Legg leggsimon

🙃
View GitHub Profile
@leggsimon
leggsimon / colour_node_debugging.md
Last active March 22, 2019 23:47
How to debug node more easily using colored console logging

Debugging Node with colours

See me talk about this at the London Node User Group

Found out today that while debugging a node application using console.log() in the terminal I can pass arguments that formats the styles in the console.

console.log('\x1b[31m', 'Hello, world', '\x1b[0m');  // red
module Main exposing (..)
import Html exposing (Html, button, div, text, h1)
import Html.App as App
import Html.Events exposing (onClick)
main =
App.beginnerProgram { model = model, view = view, update = update }
#!/usr/bin/env node
console.log('\x1b[1m','Please wait for linting to run...','\x1b[0m');
console.log('You can','\x1b[1m','skip','\x1b[0m','the precommit hook by running "git commit -n" instead','\x1b[1m', "but beware!",'\x1b[0m');
require('child_process').exec(
'make verify',
function (error, stdout) {
console.log(stdout && 'stdout: ' + stdout);
if (error !== null) {
@leggsimon
leggsimon / find-obsolete.js
Last active March 27, 2017 00:26
A shell script that finds files in a specified directory and returns the instances it is used within another directory. Used to find files that weren't ever required in another file in a repository
#!/usr/bin/env node
const shell = require('child_process');
const path = require('path')
if (process.argv.length <= 3) {
console.log(`Usage: ${__filename} path/to/directory/with/needles path/to/haystack`);
process.exit(-1);
}
@leggsimon
leggsimon / propsal.md
Created January 27, 2018 18:33
ECMAScript Proposal - Question Mark character to be allowed in IdentifierNames

ECMAScript Proposal - Question Mark character to be allowed in IdentifierNames

Outline

My proposal is for the Question Mark (?) character to be allowed in an IdentifierName.

Acording to the current ES5 spec

This standard specifies specific character additions: The dollar sign ($) and the underscore (_) are permitted anywhere in an IdentifierName.

Currently I can't think of any reason why this couldn't be ammended in a future version.

@leggsimon
leggsimon / index.js
Created March 25, 2018 19:00
Bot blocker
// mad codez
const toBool = str => {
if (!str) {
return false
}
return str === 'true'
? true
: str === 'false'
? false
: true
const querystring = require('querystring');
const qs = querystring.parse('doom=bar')
console.log(qs)
// console.log(`QS: ${qs}`) <-- This blows up
// console.log('QS: ' + qs) <-- So does this
qs.toString = function() {
return JSON.stringify(this)
const post = (userId) => {
// First check the user exists
return getUser(userId)
.then(user => {
// Ok, so the user aleady exists
// do some logic
// Lets try and delete them
return deleteUser(userId)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>WFWorkflowActions</key>
<array>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.count</string>
<key>WFWorkflowActionParameters</key>