This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Return greatest common divider of two numbers | |
function gcd($a, $b) { | |
return $b ? gcd($b, $a % $b) : $a; | |
} | |
// Returns the least common multiple of two or more numbers. | |
function lcm(...$numbers): int | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Utility class to enable very simplistic timing. | |
* | |
* Usage example: | |
* | |
* $t = new Timer(); | |
* // do something here | |
* echo $t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(function(){ | |
function wordCount(str, charlist) { | |
var len = str.length, cl = charlist && charlist.length, | |
chr = '', tmpStr = '', i = 0, c = '', wC = 0, reg = '', match = false; | |
var _preg_quote = function(str) { | |
return (str + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, '\\$1'); | |
} | |
var _getWholeChar = function(str, i) { | |
var code = str.charCodeAt(i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From: https://stackoverflow.com/a/36079484 | |
// The unsorted data | |
let data = { | |
a: 'A', | |
c: 'C', | |
b: 'B' | |
}; | |
// Create it sorted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter an array of objects. | |
* | |
* You can pass in one or more properties on which to filter. | |
* | |
* If the key of an array is an array, then it will filtered down to that | |
* level of node. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first make sure MP4Box is install | |
sudo apt-get install gpac | |
# then run this from the command line | |
for i in *.h264; do MP4Box -add $i ${i%.*}.mp4; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from RPi import GPIO | |
from time import sleep | |
import subprocess | |
clk = 5 | |
dt = 6 | |
btn = 26 | |
# vals from output of amixer cget numid=1 | |
min = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# change the colour of the base directory depending on whether | |
# I'm in the live/staging/dev areas. Also show the user and host | |
# as well as the bash history number of the command. | |
C_DEV="\[\033[0;32m\]" # green | |
C_STAGE="\[\033[0;33m\]" # yellow | |
C_LIVE="\[\033[1;31m\]" # bold red | |
C_PATH="\[\033[0;37m\]" # white | |
C_COUNT="\[\033[0;36m\]" # cyan | |
C_NONE="\[\033[0m\]" # reset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date.timezone = "Europe/London" | |
expose_php = 0 | |
extension = phar.so | |
extension = fileinfo.so | |
extension = intl.so | |
suhosin.executor.include.whitelist = phar | |
[opcache] | |
zend_extension=opcache.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* | |
* <img src="pic.jpg" data-colour="blue" /> | |
* <img src="pic.jpg" data-colour="green" data-contrast="40" /> | |
* <img src="pic.jpg" data-colour="pink" data-brightness="30" /> | |
* <img src="pic.jpg" data-colour="#ddc258" data-contrast="40" data-brightness="30" /> | |
* <script>$(function(){ $(img['data-colour']).toner(); });</script> | |
*/ | |
;(function ($, window, document, undefined) { |