Skip to content

Instantly share code, notes, and snippets.

@Nilpo
Nilpo / CustomException.php
Last active May 10, 2020 09:03
If you intend on creating a lot of custom exceptions, I've created an interface and an abstract exception class that ensures that all parts of PHP's built-in Exception class are preserved in child classes. It also properly pushes all information back to the parent constructor ensuring that nothing is lost. This allows you to quickly create new e…
<?php
/*
* This code is free software; you can use it, redistribute it, and/or modify as you wish.
* This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY - implied or otherwise.
* This code is distributed "as is." All risk and cost are assumed by the user of the code and not the creator thereof.
* If you wish to give attribution, the original creator is Robert "Nilpo" Dunham (devnilpo@gmail.com)
*/
interface IException
{
@Nilpo
Nilpo / Session.php
Last active August 5, 2023 16:48
A simple session wrapper class to provide static OOP access to PHP sessions.
<?php
/**
* Session Helper Class
*
* A simple session wrapper class.
*
* Recommended for use with PHP 5.4.0 or higher. (Not required.)
*
* Usage Example:
// github gist Shortcode Usage: [gist id="" file=""]
function gist_shortcode( $atts ) {
extract(shortcode_atts(array(
'id' => '',
'file' => ''
), $atts));
return '<script src="https://gist.github.com/'.$id.'.js?file='.$file.'"></script>';
}
add_shortcode('gist', 'gist_shortcode');
@Nilpo
Nilpo / lazyload_google_analytics.html
Created December 26, 2013 04:47
Lazy load Google Analytics
<script type="text/javascript">
(function($) {
$("body").load(function() {
setTimeout(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}, 1);
});
})(jQuery);
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="An example of simple JavaScript animation for HTML5 meters and progress bars." />
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<p><meter id="meter" value="300" min="0" max="500">300Gb of 500Gb</meter></p>
// Conditionally Load jQuery (javascript)
// Source: https://gist.github.com/gists/902090/
var init, loadjQuery;
init = function() {
jQuery(document).ready(function() {
alert('Your Code Here');
});
};
@Nilpo
Nilpo / .bashrc
Created June 20, 2014 01:38 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@Nilpo
Nilpo / gh_hook.php
Last active August 29, 2015 14:05 — forked from webjay/gh_hook.php
<?php
/**
* This file serves as a post receive hook for a GitHub repository. It should be placed in the root of the repository.
*
* To begin, you will need to store a secret key in an environmental variable on the server.
*
* export SECRET_TOKEN=your_token
*
*
@Nilpo
Nilpo / Autoloader.php
Last active August 25, 2023 18:41
A simple recursive PHP autoloader using the RecursiveDirectoryIterator.
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Rob Dunham
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@Nilpo
Nilpo / .bashrc
Created October 1, 2014 04:48
Adds colored bash prompt, Git completion, and git branch name in the bash prompt.
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)