Skip to content

Instantly share code, notes, and snippets.

@lcherone
lcherone / gist:6b0e04d6bc6eb8306f20
Last active August 29, 2015 14:10
Random A1phaNumEr1c infinite length string function
<?php
echo passgen(20); //K4YFnMW5muf0kZTMl6h3
function passgen($length = 20)
{
// define base string - add multiplex to pad to an infinate length
$alpha = str_repeat(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
intval($length + 1)
);

Keybase proof

I hereby claim:

  • I am lcherone on github.
  • I am lcherone (https://keybase.io/lcherone) on keybase.
  • I have a public key whose fingerprint is 3741 7D7C 39BA F498 393C 700D 968E 8ABC 3112 189E

To claim this, I am signing this object:

@lcherone
lcherone / instal-lamp.sh
Last active September 16, 2017 18:35
LAMP - Apache2 (rewrite, headers enabled), PHP7, MariaDB, Git, Composer, nodejs, npm
#!/bin/bash
#
set -e
export DEBIAN_FRONTEND=noninteractive
source /etc/environment && export PATH && export HOME='/root'
# Set working vars, change these to suit
#
# Application Name
@lcherone
lcherone / lxc-autostart.sh
Last active September 20, 2017 04:03
LXD apply autostart [true|false] to all containers and default profile.
#!/bin/bash
#
# Apply autostart to all containers and default profile.
# - Especially handy if containers have their own autostart value.
# - Could be used for any config value with a tweek.
#
# ask
while true; do
@lcherone
lcherone / lxc-stop.sh
Created September 20, 2017 04:15
LXD stop all running containers
#!/bin/bash
#
# Stop all running containers
#
# stop running containers
for container in $(lxc list volatile.last_state.power=RUNNING -c n --format csv); do
lxc stop "$container"
done
@lcherone
lcherone / utc.date.js
Created September 23, 2017 10:45
Javascript Date.UTC mysql date converter
/**
* Date.UTC mysql date converter
*
* @author Lawrence Cherone <lawrence@cherone.co.uk>
*/
var UTC = (function() {
var _Date = function(year, month, day, hour, minute, second) {
// year is string string date
if (typeof year === "string" && year != '' && month == undefined && day == undefined) {
var regex_date = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])?$/;
@lcherone
lcherone / phone-codes.txt
Last active September 23, 2017 10:51
Mobile *# hidden device codes
Android
*#06# - IMEI
*#0*# - Sensor Tests
*#9900# - SysDump
*#0808# - USBSettings
*#0011# - ServiceMode
*#0228# - BatteryStatus
*#1234# - Version
*#2663# - Firmware version
@lcherone
lcherone / xor.php
Last active October 1, 2017 12:24
xor
<?php
$xor = function ($str, $key = 192) {
for ($i = 0; $i < strlen($str); $i++) {
$str[$i] = chr(ord($str[$i]) ^ $key);
}
return $str;
};
$enc = $xor("xorme");
$dec = $xor($enc);
@lcherone
lcherone / Fibonacci.php
Created October 1, 2017 18:07
Fibonacci sequence generator class, a play with PHP7 features.
<?php
declare(strict_types=1);
/**
* Fibonacci sequence generator, a play with PHP7 features.
* @author Lawrence Cherone <cherone.co.uk>
*/
class Fibonacci {
private $sequence = [];
@lcherone
lcherone / code.php
Last active November 22, 2017 13:19
Asymmetric encryption using PHP (the alice and bob story)
<?php
// define an example, our people, messages and their keys
$people = [
'alice' => [
'keys' => gen_keys(),
'msg' => 'Hi Bob, I\'m sending you a private message'
],
'bob' => [
'keys' => gen_keys(),