Skip to content

Instantly share code, notes, and snippets.

Avatar
🍵
(ू˃̣̣̣̣̣̣︿˂̣̣̣̣̣̣ ू)

Luke Hedger lukehedger

🍵
(ू˃̣̣̣̣̣̣︿˂̣̣̣̣̣̣ ू)
View GitHub Profile
@lukehedger
lukehedger / scanDir.php
Created Jul 1, 2014
PHP directory scan
View scanDir.php
<?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 Jul 9, 2014
mkdir and cd into it
View mkdircd.bash
$ mkdir newdir && cd $_
@lukehedger
lukehedger / import.html
Last active Aug 29, 2015
HTML Imports/Templates example
View import.html
<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 Jul 29, 2014
XMLHttpRequest
View xhr.js
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 Aug 5, 2014
Crazy Mustache syntax highlighting with Liquid/Pygments on Jekyll
View pygmentStashes.md

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>
</template>
@lukehedger
lukehedger / crypto-ify.coffee
Created Aug 11, 2014
AES encryption with CryptoJS and Browserify
View crypto-ify.coffee
# 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 Aug 11, 2014
Nested If/Then/Else in CoffeeScript
View nestedIf.coffee
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 Aug 13, 2014
UK Postcode RegExp
View UKPostcode.md

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 Aug 29, 2015
Kill sudo for npm
View nonpmsudo.bash
$ 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 Sep 24, 2014
Simple Angular directive
View directives.js
'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)