Skip to content

Instantly share code, notes, and snippets.

View martynchamberlin's full-sized avatar

Martyn Chamberlin martynchamberlin

View GitHub Profile
@martynchamberlin
martynchamberlin / jekyll-post
Last active April 30, 2017 04:40
Jekyll post
#!/usr/bin/python
"""
jekyll-post - this is a simple script that will create and initialize a new
Jekyll post file. The default is a markdown file (.md) and the yaml options
listed below will be part of the initialization.
jekyll-post [-w] [-d date] [title]
title the title of the post wrapped in quotes, e.g. "post title here"
@martynchamberlin
martynchamberlin / example.html
Last active February 27, 2017 02:07
How to conditionally load Google Font client-side while avoiding FOUT
<html>
<head>
<script>
/**
* This function used with gratitude from
* http://stackoverflow.com/a/34666534/1591507
* I want to refactor this to ES6 so badly but
* since it has to reside in the DOM to avoid FOUT,
* we can't transpile with Babel unfortunately
*/
@martynchamberlin
martynchamberlin / bench.html
Last active September 12, 2016 20:39
Benchmarking localStorage in small big versus big small
<script>
// Store and retrieve 1000 100-byte items. Then store and retrieve 10 10000-byte item
let test = (numBlocks, byteSze) => {
let bytes = 'a';
for (let i = 0; i < byteSze; i++) {
bytes += 'a';
}
@martynchamberlin
martynchamberlin / orderBySubArray.php
Last active January 4, 2016 13:38
Sort a PHP array based on a subarray.
<?php
function orderBySubArray( &$array, $new_key = 'order', $order = 'ascending', $start_at = 1 )
{
$output = array();
$count = count( $array );
$i = ( $order == 'ascending' ) ? $start_at : $count;
for ( $j = 1; $j <= $count; $j++ )
{
@martynchamberlin
martynchamberlin / index.html
Last active December 27, 2015 20:09
Simple show/hide structure. I build this an absolute ton and need a place to reference it so I'm not constantly writing the same thing over and over again. The beauty of this structure is that you can have an unlimited number of .toggle elements on a page and there will not be any conflict. No unique IDs required.
<div class="toggle">
<a href="#" class="read-more">Read more</a>
<div class="hidden hiding" style="display:none">This text toggles back and forth</div>
</div>
@martynchamberlin
martynchamberlin / main.cpp
Last active December 27, 2015 17:49
Console C++ application. Gets user input and checks to see if it is a valid integer.
#include <iostream>
using namespace std;
bool isInt(char tempNumber);
int main()
{
char tempNumber[10];
while ( true )
@martynchamberlin
martynchamberlin / index.html
Last active December 27, 2015 07:09
This is the most drop-dead simple jQuery slideshow you could possibly have. Nothing fancy at all, but mind-boggling get-out-of-the-way simple. Actually using it for a client project.
<div id="slider">
<img>
<input type="hidden" value="/wp-content/themes/geek/images/slide1.png">
<input type="hidden" value="/wp-content/themes/geek/images/slide2.png">
<input type="hidden" value="/wp-content/themes/geek/images/slide3.png">
<input type="hidden" value="/wp-content/themes/geek/images/slide4.png">
</div>
@martynchamberlin
martynchamberlin / fibonacci.js
Last active December 26, 2015 19:29
Here's a pretty decent implementation of the fibonacci sequence. It's taken from pseudocode from my Discrete Mathematics textbook and modified to be compliant with the true sequence (see lines 7 and 8). I'm not getting any console errors when I call the function without the second parameter so it's all good. Wish Javascript made optional paramet…
function fibonacci(n, recursive)
{
if ( n == 0 )
return 0;
if ( n < 3 )
return 1;
if ( recursive !== true )
n--;
return fibonacci( n-1, true) + fibonacci( n-2, true);
}
@martynchamberlin
martynchamberlin / fibonacci.js
Created October 28, 2013 18:21
Here's a bad, bad implementation of Fibonacci sequence. And yet it's the best I'm capable of coming up with by myself.
function fibonacci( n )
{
prev_1 = total = 0;
prev_2 = 1;
if ( n == 0 )
return 0;
if ( n < 3 )
return 1;
for ( var i = 0; i < n - 1; i++ )
{
@martynchamberlin
martynchamberlin / functions.php
Last active December 23, 2015 00:59
I highly recommend the Query Multiple Taxonomies (http://scribu.net/wordpress/query-multiple-taxonomies/) plugin. It lets you build custom post types and custom taxonomies. But what if you are in a WordPress post type and want to print that a taxonomy of that post to the screen? "Stupid idea!" You say. "I specify that post's taxonomies within th…
<?php
function z_get_taxonomy( $var )
{
extract( shortcode_atts( array(
'name' => ''
), $var ) );
$postID = get_the_ID();
if ( ! empty( $name ) )
{