Skip to content

Instantly share code, notes, and snippets.

Liam Hammett imliam

Block or report user

Report or block imliam

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
imliam / take.php
Last active Jan 15, 2020
Run functions consecutively by piping through the result of one into the next.
View take.php
if (! function_exists('take')) {
* Run functions consecutively by piping through the result of one
* into the next.
* @param mixed $value A value
* @return object
View static_or_non_static.php
* Allows a method in a class to be called either statically or instanced.
* To use, ensure custom method names are camelCase starting withthe word
* "either". For example, a method defined as "eitherGetResults()"
* can be called in either of the two following ways:
* $exampleObject->getResults()
imliam / bind_methods.php
Created Jan 10, 2018
Trait to dynamically bind methods to a class.
View bind_methods.php
trait BindMethods
private $boundMethods = [];
public function bindMethod($methodName, $method) {
$this->boundMethods[$methodName] = Closure::bind($method, $this, get_class());
imliam / safe.php
Last active Jan 11, 2018
Safely attempt to call methods on something you believe to be an object.
View safe.php
if (! function_exists('safe')) {
* Safely attempt to call methods and properties on something you believe
* to be an object but may be null, using a hidden anonymous class for
* syntactical sugar to keep your application logic looking simple
* and clean.
* @param object $value The suspected object.
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
title emoji description
art 🎨 Improving structure/format of the code.
zap ⚡️ Improving performance.
fire 🔥 Removing code or files.
bug 🐛 Fixing a bug.
ambulance 🚑 Critical hotfix.
sparkles Introducing new features.
memo 📝 Writing docs.
rocket 🚀 Deploying stuff.
View replace-text.sql
* MySQL Replace Text
* Replace a certain bit of text inside a MySQL entry. For example, replacing
* every instance of one word with another.
UPDATE table_name
SET column_name = REPLACE(column_name, 'good', 'amazing')
WHERE column_name LIKE 'Jannet%'
View listAsSentence.js
* Create an English sentence string from an array of items.
* @param {array} array [description]
* @param {string} separator Separator for list items. Defaults to ","
* @param {string} finalSeparator Separator for last item. Defaults to "and"
* @return {string} List as an English sentence.
function listAsSentence(array, separator, finalSeparator)
imliam / switch-column-values.sql
Created Oct 25, 2017
Switch the values between two columns of the same row using a variable.
View switch-column-values.sql
| Switch Column Values
| Switch the values between two columns of the same row using a variable.
| Assigns a temporary variable "@tmp" to store "columnA", then replaces
| the columnA with columnB, then columnB with "@tmp".

Regex to format and validate for usernames (including games by Atelier 801), with the following rules:

  • Must be between 3 and 20 characters
  • May only contain alphanumeric characters and underscores
  • First character must be alphabetical or a plus +
You can’t perform that action at this time.