Skip to content

Instantly share code, notes, and snippets.

View sidouglas's full-sized avatar

Simon Douglas sidouglas

  • Sydney, Australia
View GitHub Profile
@sidouglas
sidouglas / sh
Created January 8, 2020 10:53
Bash/Shell script set type to php
#!/usr/bin/php
@sidouglas
sidouglas / sh
Created January 8, 2020 10:54
Bash/Shell get directory cwd path
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
@sidouglas
sidouglas / index.php
Created January 8, 2020 10:55
Php output buffering using ob_start
<?php ob_start(); ?>
// something that's printing
<?php
$contents = ob_get_contents();
ob_end_clean();
return $contents;
?>
@sidouglas
sidouglas / index.php
Created January 8, 2020 10:58
Php String replace token
//example $theString = '<hi>' => '<em>hi</em>'
<?=strtr($theString, ['<' => '<em>', '>' => '</em>'])?>
@sidouglas
sidouglas / TemplateTrait.php
Created January 8, 2020 11:02
Simple PHP Supplant Templating for HTML
<?php
trait TemplateTrait
{
/**
* supplant
* Replaces %tokens% inside a string with an array key/value
* strings not replaced are removed
* @param $string :string,
* @param $array :array
* @return string
@sidouglas
sidouglas / delete-transient.sql
Last active June 30, 2020 04:57
Delete Transients from WordPress
DELETE FROM `wp_options` WHERE `option_name` LIKE ('%_transient_%');
DELETE FROM `wp_options` WHERE `option_name` LIKE ('%_site_transient_%');
@sidouglas
sidouglas / list.sh
Created January 8, 2020 11:10
npm list node_modules installed globally or locally
npm list -g --depth=0 2>/dev/null #remove -g for local
@sidouglas
sidouglas / stringify.js
Created January 8, 2020 11:15
Console.log for a JSON.Stringify Circular reference
var cache = [];
var x = JSON.stringify(YOUR_VARIABLE_OBJECT_HERE, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
@sidouglas
sidouglas / throttle.sh
Created January 14, 2020 00:26
Mac Check if Processor is throttling shell script
pmset -g thermlog
@sidouglas
sidouglas / Set Default Shell to (zsh nvm yarn)
Created February 5, 2020 23:17
Set default shell to zsh
# set default shell to zsh
set -g default-command /bin/zsh
set -g default-shell /bin/zsh