Skip to content

Instantly share code, notes, and snippets.

class Lightbulb_Interface {
// switch_on should have an arity of 0
// it should turn on the thing.
switch_on() {}
// switch_off should have an arity of 0.
// it should turn off the thing.
switch_off() {}
}
@davemackintosh
davemackintosh / markdown-to-html.sh
Created July 27, 2016 09:43
heh, who needs Jekyll or Any other thing for Markdown to templated HTML.
#!/bin/bash
# Loop over each found markdown file.
for file in content/*.md; do
# Check it's an actual readable file.
if [ -e "$file" ] ; then
# Get our 💩 together.
TEMPLATE=`cat template.html`
CONTENT=`cat "$file" | pandoc --no-highlight -f markdown`
@davemackintosh
davemackintosh / ShareButton.jsx
Created May 17, 2016 21:05 — forked from jamesslock/ShareButton.jsx
ReactJS Share Buttons
import React, { PropTypes } from 'react';
import Button from '../components/Button.jsx';
import Icon from '../components/Icon.jsx';
module.exports = React.createClass({
render: function () {
const {
className,
classNameIcon,
children,
@davemackintosh
davemackintosh / test.js
Created May 10, 2016 15:48
TIL more about fat arrow scoping.
const notifications = models.notifications
notifications
.find({whatever})
.exec((err, notifs) => {
notifications.destroy({whatever})
// ^- Notifications here is undefined because this block has a definition of notifications later.
// It is dereferenced from this local scope pending the definition below.
// This is a really simplified example.
// All the transform types.
const types = [
"translate",
"translateX",
"translateY",
"scale",
"scaleX",
"scaleY",
"rotate",
"skew",
@davemackintosh
davemackintosh / bw-contrast-hex.js
Created April 16, 2016 10:18
Output black or white hex to contrast any hex colour
function contrast_colour(hex) {
//- Get rid of any hashes.
var colour = hex.replace(/\#/g, "")
//- Get the luminance.
var R = parseInt(colour.substring(0, 2), 16)
var G = parseInt(colour.substring(2, 4), 16)
var B = parseInt(colour.substring(4, 6), 16)
// If it's over half the total of 765 (255 * 3), it's lighter
@davemackintosh
davemackintosh / .htaccess
Created March 30, 2016 14:19
Works locally, Heroku says recursion loop. I don't see it.
<ifModule mod_rewrite.c>
RewriteEngine On
# Set up a rule for the Apple site association.
RewriteRule ^apple\-app\-site\-association$ /apple-app-site-association.php [L]
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteCond %{REQUEST_URI} !^(bower_components|assets|apple\-app\-site\-association)
@davemackintosh
davemackintosh / bench.js
Last active January 21, 2016 12:42 — forked from AdriVanHoudt/bench.js
Mini benchmark Hoek.unique vs Set
"use strict"
// used in benchmarks.
const SAMPLE = 5000000
const Hoek = require('hoek')
const array = []
for (let i = 0; i < SAMPLE; ++i) {
array.push(i * Math.floor(Math.random() * (10 - 1 + 1)) + 1)
}
@davemackintosh
davemackintosh / map-to-json.js
Last active August 7, 2023 15:49
Convert ES6 `Map`s to a standard JSON object without effing Babel.
/**
* Convert a `Map` to a standard
* JS object recursively.
*
* @param {Map} map to convert.
* @returns {Object} converted object.
*/
function map_to_object(map) {
const out = Object.create(null)
map.forEach((value, key) => {
@davemackintosh
davemackintosh / blob_to_buffer.js
Created December 12, 2015 14:26
Electron blob to buffer, I made this to use with the nativeImage class.
function blob_to_buffer(blob, callback) {
// Create a file reader instance.
const file_reader = new FileReader()
// Listen to when reading is finished and
// run the callback with a buffer.
file_reader.addEventListener("loadend", event => {
if (event.error) {
callback(event.error)
}