Skip to content

Instantly share code, notes, and snippets.

View martynchamberlin's full-sized avatar

Martyn Chamberlin martynchamberlin

View GitHub Profile
@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 / 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 / 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 / gist:4515705
Last active December 11, 2015 00:19
In C#, all constructors in polymorphism will fire, starting at the top of the tree and working down. Sometimes this isn't the desired behavior. Here's a potential workaround using a simple Window Console application.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
B myObj = new B();
// comment the next line to disable parent constructor
myObj.Initialize();
}
@martynchamberlin
martynchamberlin / gist:5278521
Last active December 15, 2015 14:59
Force SSL on WordPress Pages, in this case, a page with an ID of 2
<?php
$using_ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443;
add_action('wp', 'check_ssl');
function check_ssl()
{
// Page ID 2 must be https
if (is_page(2) && !$using_ssl)
{
header('HTTP/1.1 301 Moved Permanently');
@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 / sticky_footer.js
Last active December 17, 2015 19:19
Sticky footer using jQiery
@martynchamberlin
martynchamberlin / app.php
Created June 8, 2013 20:57
Code for moving subscribers from one list to another in AWeber.
<?php session_start(); ?>
<form action="" method="post">
<div>
<label>Old list name</label>
<input type="text" name="list_name" <?php if (isset($_SESSION['list_name'] )) echo 'value="' . $_SESSION['list_name'] . '"'; ?>
</div>
<div>
<label>New list name</label>
@martynchamberlin
martynchamberlin / demo.js
Last active December 20, 2015 08:39
Super easy way to give similar items a unique DOM identifier using jQuery
jQuery(document).ready(function( $ )
{
var i = 1;
$('nav li').each(function()
{
$(this).addClass('item_' + i );
i++;
});
});