Skip to content

Instantly share code, notes, and snippets.

View lukehedger's full-sized avatar
🍵
(ू˃̣̣̣̣̣̣︿˂̣̣̣̣̣̣ ू)

Luke Hedger lukehedger

🍵
(ू˃̣̣̣̣̣̣︿˂̣̣̣̣̣̣ ू)
View GitHub Profile
@lukehedger
lukehedger / scanDir.php
Created July 1, 2014 14:53
PHP directory scan
<?php
header('Content-Type: application/json');
function scan(){
$dirOne = scandir('../data/one');
$dirTwo = scandir('../data/two');
$response = (object) array('dirOne' => $dirOne, 'dirTwo' => $dirTwo);
@lukehedger
lukehedger / mkdircd.bash
Created July 9, 2014 08:46
mkdir and cd into it
$ mkdir newdir && cd $_
@lukehedger
lukehedger / import.html
Last active August 29, 2015 14:04
HTML Imports/Templates example
<html>
<head>
<!-- Link to import file -->
<link rel="import" href="template.html" name="template1">
</head>
<body>
<!-- a container div with an id to match the name attribute of the import link -->
<div class="container" id="template1">
<!-- the contents of template.html will be inserted here at runtime -->
@lukehedger
lukehedger / xhr.js
Created July 29, 2014 08:46
XMLHttpRequest
request = new XMLHttpRequest();
request.open('GET', '/data/data.json', true);
request.onload = function() {
if (this.status >= 200 && this.status < 400){
data = JSON.parse(this.response);
console.log(data);
} else {
console.log("Data error");
}
@lukehedger
lukehedger / pygmentStashes.md
Created August 5, 2014 16:22
Crazy Mustache syntax highlighting with Liquid/Pygments on Jekyll

To escape double-stashes (as seen in Mustache, Handelbars templates etc) within Liquid/Pygments highlight blocks:

You've got to put this {{ " directly before the opening double-stashes and this " }} directly before the closing double-stashes.

So say you're trying to highlight something like this:

<template attr='{{ value }}'>
    <li>{{ this }}</li>
@lukehedger
lukehedger / crypto-ify.coffee
Created August 11, 2014 11:33
AES encryption with CryptoJS and Browserify
# Include Crypto JS modules as required
CryptoJS = require 'crypto-js'
AES = require 'crypto-js/aes'
# then use like so:
str = "Message to encrpyt"
passcode = "wu gang chops the tree"
hash = AES.encrypt(str, passcode).ciphertext.toString(CryptoJS.enc.Base64) # => hI524rbTeezmKq9BSl1b0ZOtgGAu+4y8X4FAk/VAMh8=
@lukehedger
lukehedger / nestedIf.coffee
Created August 11, 2014 15:05
Nested If/Then/Else in CoffeeScript
x = if a then (if b then 1 else 0) else 0
# a and b => x is 1
# a and !b => x is 0
# !a => x is 0
@lukehedger
lukehedger / UKPostcode.md
Created August 13, 2014 15:11
UK Postcode RegExp

Official Gov UK postcode regular expression:

^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})$

@lukehedger
lukehedger / nonpmsudo.bash
Last active August 29, 2015 14:05
Kill sudo for npm
$ npm config set prefix ~/npm
$ echo prefix = ~/.node >> ~/.npmrc
# append this to .bashrc or .bash_profile: export PATH="$PATH:$HOME/.node/bin"
@lukehedger
lukehedger / directives.js
Created September 24, 2014 11:18
Simple Angular directive
'use strict';
// declare app-level module
var app = angular.module('app', []);
// register directive
app.directive('partial', function () {
return {
templateUrl: "partial.html", // url to template
restrict: "AE" // restrict directive trigger to attribute (A) and element (E), not classname (C)