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 / conditionals.js
Last active December 15, 2015 21:36
Simplifying complex conditional expressions
/**
* The problem
*/
var A = true;
var B = true;
var C = false;
var D = false;
if ( A && B || C && ! D ) {
@martynchamberlin
martynchamberlin / bootstrap-cheat.css
Last active June 1, 2018 21:41
Bootstrap Cheat Sheet
/*
Here's a brief explanation of the breakpoints
lg: 1200+
md: 992-1199
sm: 768-991
xs: 767-
*/
@martynchamberlin
martynchamberlin / index.html
Created July 16, 2015 18:28
Scalabe circle with pure CSS
<div class="wrap">
<div class="left">
<div class="box-container-outer">
<div class="box-container">
<div class="box">
<div class="center-vertical">A</div>
</div>
</div>
</div>
Left Content Area
@martynchamberlin
martynchamberlin / app.js
Last active October 18, 2015 00:28
Simple way to cache the information about the logged in user, using an AngularJS service
/** This file serves as a usage example **/
angular.module("MyApp").controller("homeCtrl", ["$scope", "$rootScope", "UserService", homeCtrl]);
function homeCtrl($scope, $rootScope, UserService) {
UserService.GetUser().then(function(user) {
console.log( user.FirstName );
}, function() {
console.log( 'An error occurred' );
});
}
@martynchamberlin
martynchamberlin / LinkedList.cpp
Last active August 29, 2015 14:14
LinkedList example
//
// LinkedList.c
// linked_lists
//
// Created by Martyn Chamberlin on 2/5/15.
// Copyright (c) 2015 Martyn Chamberlin. All rights reserved.
//
#include "LinkedList.h"
#include <iostream>
@martynchamberlin
martynchamberlin / site.js
Created October 25, 2014 03:36
Remove WPAdmin Bar in WordPress
/**
* By default you can rmeove a single user's admin bar in WordPress.
* That's cool but the problem of course is that you have to do this
* for every single user. If you are using software like Wishlist
* Member where new users are being added all the time, this is bad.
* The solution is to programmatically remove the admin bar accross
* the board. I've experimented doing this several ways and this is
* the best one in my expereince.
*/
@martynchamberlin
martynchamberlin / centerVertically.js
Created September 16, 2014 02:32
centerVertically.js—a simple extension to the jQuery library that allows you to vertically center most anything.
/**
* centerVertically() takes a given DOM element and centers
* it vertically within the parent element. If the height
* of the browser is less than this element's height, then
* the original margin relative to top is restored until
* the window gets larger again.
*
* Note that this function extends the jQuery library and
* therefore requires it before this function can be
* defined.
@martynchamberlin
martynchamberlin / functions.php
Created August 27, 2014 19:59
Remove White Space Between <li> Elements in a Genesis Menu
<?php
/**
* Having `display: inline-block` works great as long as there isn't white space.
*/
add_filter('genesis_do_nav', 'remove_whitespace');
function remove_whitespace( $str )
{
$str = str_replace( "\r\n", "", $str );
$str = str_replace( "\r", "", $str );
@martynchamberlin
martynchamberlin / example_of_static_in_php.php
Last active August 29, 2015 14:03
PHP overloads the `static` keyword. In instance variables, it means the classical OOP usage. In local variables (stack instead of heap) it means something else. This code demonstrates that something else.
<?php
function get_random_num( $start = 1, $finish = 2 )
{
static $rand;
if ( ! isset( $rand ) )
{
$rand = rand( $start, $finish );
}
return $rand;