Skip to content

Instantly share code, notes, and snippets.

View MattMS's full-sized avatar
🤔

Matt McKellar-Spence MattMS

🤔
View GitHub Profile
@MattMS
MattMS / BasicWinForms.fs
Last active July 20, 2019 07:32
Basic F# WinForms demo
open System
open System.Windows.Forms
let makeButton label click =
let button = new Button()
button.Text <- label
let clickHandler = new EventHandler(click)
button.Click.AddHandler clickHandler
button
@MattMS
MattMS / paragraphs.js
Last active June 25, 2019 09:43
Text to HTML conversion.
var split_p_and_br = s => s.trim().split(/\n\n/).map(s => s.replace(/\n/g, '<br />'))
var split_p = s => s.trim().split(/\n\n/).map(s => s.replace(/\n/g, ' '))
var join_p = p => p.join('</p><p>')
var fin = t => `<p>${t}</p>`
var a = `
hello
@MattMS
MattMS / not_redux.js
Last active May 25, 2019 02:35
Messing around with Ramda to create a state-changing thing.
/* Example of something that is inspired by Redux, but totally not a replacement for it.
This is NOT intended to be used in anything serious; go find a proper library instead.
[MIT licensed](https://opensource.org/licenses/MIT)
So do whatever you want with any or all of this but don't blame me for anything.
Copyright 2019 Matt McKellar-Spence
*/
const {append, cond, inc, join, lensIndex, lensPath, map, over, pathEq, pipe, prop, T, toPairs, toString} = require('ramda')
@MattMS
MattMS / h.py
Created May 12, 2019 09:16
Create HTML with Python
def _add_global(name, value):
globals()[name] = value
def _replace_underscore(text):
return text.replace('_', '-')
class h:
def __init__(self, *children, **attributes):
self.attributes = attributes
self.children = children
@MattMS
MattMS / eat.md
Last active March 21, 2019 12:34
Simplify calling curried functions.

Eat

Use eat to simplify calling curried functions.

You can rewrite a(b)(c) as eat(a, b, c).

CoffeeScript

eat = (curries...)-&gt;
@MattMS
MattMS / time format examples.md
Last active July 26, 2018 10:02
Convert the current UTC time to different formats.

Time format examples

Gets the current UTC time to seconds accuracy (max available with date). Using date and sed so these can run in Alpine Linux.

As file path

For example: 1999/12/31/23/59/59

@MattMS
MattMS / Python logger list.py
Created January 24, 2018 06:03
List the names of all loggers.
# Need to import at this level.
# Cannot `from logging.Logger.manager import loggerDict`.
import logging
print(sorted(logging.Logger.manager.loggerDict.keys()))
# https://mail.python.org/pipermail/python-list/2012-June/625343.html
# by Michael Hrivnak
@MattMS
MattMS / Google_Cloud_access_token.sh
Created March 10, 2017 12:34
Get an access token for future requests to Google Cloud APIs
access_token=$(curl
-H "Metadata-Flavor: Google"
--show-error
--silent
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token?alt=text
| awk '$1 == "access_token" { print $2 }')
@MattMS
MattMS / Docker_remove_untagged_Images.sh
Created November 13, 2017 07:47
Delete all Docker Images with no ("<none>") tag.
#!/bin/sh
docker images | awk '$2 == "<none>" {print $3}' | xargs docker rmi

Compose Express calls

compose = (calls)-> (req, res, next)->
	if calls.length
		calls[0] req, res, ->
			call = compose calls.slice 1
			call req, res, next
	else if next
		next()