Skip to content

Instantly share code, notes, and snippets.

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

Luke Hedger lukehedger

🍵
(ू˃̣̣̣̣̣̣︿˂̣̣̣̣̣̣ ू)
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / mkdircd.bash
Created July 9, 2014 08:46
mkdir and cd into it
$ mkdir newdir && cd $_
@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 / pythonServer.bash
Created June 27, 2014 10:45
Python SimpleHTTPServer
$ python -m SimpleHTTPServer 8000
@lukehedger
lukehedger / OO.js
Created June 24, 2014 11:46
Skeleton object-orientated JS
var app = new App('arg');
App = function(arg) {
this.APP_CONSTANT = 0;
this.appVar = arg;
this._init();
}
@lukehedger
lukehedger / kill-jekyll.md
Last active February 28, 2022 16:57
Kill Jekyll server

Stopping a Jekyll server with ctrl-z can cause issues as the process is not stopped fully. To kill it:

$ lsof -wni tcp:4000
$ kill -9 <PID of process>

And next time, use crtl-c to stop.