Skip to content

Instantly share code, notes, and snippets.

View ear1grey's full-sized avatar

Rich Boakes ear1grey

View GitHub Profile
@ear1grey
ear1grey / closureex.js
Created February 27, 2014 13:43
An example javascript closure, with public / private vars and a shortcut function.
var example = (function() {
var
fn1 = function() {return fn2();},
fn2 = function() {return "b";};
return {
"pubfn1": fn1
};
@ear1grey
ear1grey / stars.js
Created February 23, 2015 21:58
Static stars, in SVG, added to any page with `<script src="stars.js"></script>`, because, well, stars of course.
var rdfx = rdfx || {};
rdfx.stars = function() {
var
c,
svg,
ns = "http://www.w3.org/2000/svg",
cols = [
"#fff", "#777", "#333", "#333",
"#222", "#222", "#222", "#111",
@ear1grey
ear1grey / fmmv
Created July 21, 2015 08:36
Front Matter Move: Rename files in a folder based on the date contained in jekyll/markdown frontmatter
#!/bin/sh
# extracts date from file in the format
# date: 2013-08-23 14:52:59
# and prepends this to the filename
for f in *.md; do
c="$(grep -Eo 'date:\W(....-..-..)' $f | cut -d: -f2 | xargs)"
mv "$f" "$c-$f"
done
@ear1grey
ear1grey / greetfunction.java
Created September 30, 2016 15:00
Greet functions in various languages.
/* Prints a greeting */
class Greeter {
public void greet(String name) {
System.out.println(
"Hello " + name
);
}
}
/* Prints a greeting */
class Greeter {
public void greet(String name) {
System.out.println(
"Hello " + name
);
}
}
@ear1grey
ear1grey / url.svg
Last active November 22, 2016 11:16
url parts colour coded (with hideous colours)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ear1grey
ear1grey / data.json
Created February 23, 2017 07:03
Anscombe's Quartet as JSON
{
"sets": {
"set1": [
[10.0,8.04],
[8.0,6.95],
[13.0,7.58],
[9.0,8.81],
[11.0,8.33],
[14.0,9.96],
[6.0,7.24],
@ear1grey
ear1grey / scale-example.js
Created November 1, 2017 14:39
Example of using context.scale in HTML5 canvas
let can = document.createElement('canvas');
let c = can.getContext("2d");
document.body.appendChild(can);
can.width = 300;
can.height = 500;
can.style = "border: dashed black thin;";
// Calculate scale value so that using dimensions
@ear1grey
ear1grey / uop_logo_pride.svg
Last active June 3, 2020 12:38
Adjust diagonal red.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Circles</title>
<p>A little example of how <b style="color: blue;">sine</b> and <b style="color: red;">cosine</b> combine to draw a circle.
<p>The <b style="color: blue;">blue</b> line shows a <b style="color: blue;">sine</b> wave travelling along the x axis. For values of <i>i</i> between 0 and <abbr title="this is Tau, which = 2π">τ</abbr>, the wave starts from the bottom of the canvas before sweeping up to the top and then back down.
<p>The <b style="color: red;">red</b> line shows how (for the same values of i, and when plotted on a vertical instead of a horizontal axis) a cosine wave does not start at the edge of the canvas, but instead starts in the middle, so it sweeps right then left, before return to the middle.