Skip to content

Instantly share code, notes, and snippets.

@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 / 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
// All the transform types.
const types = [
"translate",
"translateX",
"translateY",
"scale",
"scaleX",
"scaleY",
"rotate",
"skew",
@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.
@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 / 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`
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() {}
}
class Frontroom_Light extends Lightbulb_Interface {
}
"use strict"
const Joi = require("joi")
const my_class_schema = require("./schema")
class Interface {
constructor() {
// Get the members on this class.
const class_funcs = Object.getOwnPropertyNames(Object.getPrototypeOf(this))
const class_as_object = {}
"use strict"
const {symbols} = require("./recommended")
class Interface {
constructor() {
// Somewhere to keep the errors.
const errors = new Set()
// Get the symbolised field with our