Skip to content

Instantly share code, notes, and snippets.

View itsliamjones's full-sized avatar

Liam Jones itsliamjones

View GitHub Profile
@itsliamjones
itsliamjones / php5-spaceship-operator.php
Last active May 10, 2016 09:24
PHP5 Three way comparison (Spaceship Operator)
<?php
/**
* PHP5 Three way comparison
*
* PHP7 This wouldn't be needed, instead you would do something along the lines of -
* if/switch ($left <=> $right) { ... }
*
* @param integer $left
* @param integer $right
@itsliamjones
itsliamjones / string-contains.php
Last active May 10, 2016 09:26
Test to see if string contains ALL needles
<?php
/**
* Test to see if string contains ALL needles
*
* @param array $needles
* @param string $haystack
*
* @return boolean
*/
@itsliamjones
itsliamjones / array-unique-fast.php
Last active May 26, 2016 13:52
PHP's inbuilt array_unique sucks, here's a significantly faster replacement for it
<?php
/**
* PHP's inbuilt array_unique sucks, here's a significantly faster replacement for it
*
* @param array $array
*
* @return array
*/
function array_unique_fast($array)
@itsliamjones
itsliamjones / array-value-recursive.php
Created May 26, 2016 13:54
Get all values from specific key in a multidimensional array, similar to array_columns
<?php
/**
* Get all values from specific key in a multidimensional array
*
* @param string $key key(s) of value you wish to extract
* @param array $arr where you want
*
* @return null|string|array
*/
# Assume we are in your home directory
cd ~/
# Clone the repo from GitLab using the `--mirror` option
$ git clone --mirror git@your-gitlab-site.com:mario/my-repo.git
# Change into newly created repo directory
$ cd ~/my-repo.git
# Push to GitHub using the `--mirror` option. The `--no-verify` option skips any hooks.
@itsliamjones
itsliamjones / .bowerrc
Created July 3, 2016 16:14 — forked from curiouslychase/.bowerrc
Gist for example bower project blog post.
{
"directory": "src/_lib",
"json": "bower.json"
}
@itsliamjones
itsliamjones / output-fraction.html
Created July 25, 2016 08:58
Pretty-ish way of outputting a fraction in HTML
1<sup>1</sup>&frasl;<sub>2</sub>
@itsliamjones
itsliamjones / curl-repo.txt
Created August 11, 2016 11:14
Use cURL to download a GitHub repository, useful for building docker images
curl -sL https://github.com/user-or-org/repo/archive/sha1-or-ref.tar.gz | tar xz
Replace user-or-org, repo, and sha1-or-ref accordingly.
If you want a zip file instead of a tarball, specify .zip instead of .tar.gz suffix.
@itsliamjones
itsliamjones / click-register.js
Last active August 15, 2016 15:56
Example register for click delegation
function ClickRegister(global, parent, debug) {
var parent = parent || document,
debug = !!debug,
register = [];
var action = function (event) {
var target = event.target || event.srcElement;
if (debug) {
console.group("click register debugging");
@itsliamjones
itsliamjones / ruleset.xml
Created December 1, 2016 12:20 — forked from gsherwood/ruleset.xml
PSR2 with tabs instead of spaces
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>PSR2 with tabs instead of spaces.</description>
<arg name="tab-width" value="4"/>
<rule ref="PSR2">
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
</rule>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>