Skip to content

Instantly share code, notes, and snippets.

Lawrence Cherone lcherone

Block or report user

Report or block lcherone

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
View php.md

You can achieve this by using the [modulus operator][1].

<?php
$result = [
    ['id' => 1, 'product_name' => 'a'],  
    ['id' => 2, 'product_name' => 'b'],  
    ['id' => 3, 'product_name' => 'c'],  
    ['id' => 4, 'product_name' => 'd'],  
    ['id' => 5, 'product_name' => 'e'],  
    ['id' => 6, 'product_name' => 'f'],  
@lcherone
lcherone / reelgood.md
Created Jan 8, 2018
Curl requests to access reelgood.com API
View reelgood.md

Curl requests to access reelgood.com API

<?php
$options = [
    'nocache' => 'true',
    'kind' => 0,
    'minimumScore' => 0,
    'sources' => [
        'amazon_prime',
        'fx_tveverywhere',
@lcherone
lcherone / adminer.md
Last active Jan 3, 2018
Adminer download
View adminer.md

downloads and names the file adminer.php

wget http://www.adminer.org/latest.php -O adminer.php

downloads and names the file adminer-4.2.1.php (E.G with its version number)

wget -N --content-disposition http://www.adminer.org/latest.php

@lcherone
lcherone / c9php7.sh
Created Dec 24, 2017
Cloud9 upgrade PHP 5 to 7
View c9php7.sh
#!/bin/bash
# add ppa and update
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
# install deps
sudo apt-get install -y php7.0-{dev,curl,gd,intl,mcrypt,json,mysql,opcache,bcmath,mbstring,soap,xml}
sudo apt-get install -y libapache2-mod-php7.0
@lcherone
lcherone / recursive_menu_function.md
Created Dec 24, 2017
nested recursive menu function
View recursive_menu_function.md
@lcherone
lcherone / hash.php
Created Dec 14, 2017
Basic encode an int into a short hash.
View hash.php
<?php
/**
* Encode an int into a short hash.
*
* @param int $id
* @param string|int $seed - Lock alphabet shuffle, or leave blank for random
* @return string
*/
function id_encode(int $id, $seed = null) {
$alphabet = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890');
@lcherone
lcherone / bug.php
Last active Dec 13, 2017
Addition precedence post increment bug.
View bug.php
<?php
$a = 0; echo $a+$a+$a++; //0
$a = 1; echo $a+$a+$a++; //3
$a = 2; echo $a+$a+$a++; //6
$a = 3; echo $a+$a+$a++; //9
echo PHP_EOL;
$a = 0; echo $a+$a++; //1 <-- should be 0
$a = 1; echo $a+$a++; //3 <-- should be 2
@lcherone
lcherone / guidv4.php
Last active Dec 7, 2017
guidv4 with random_bytes()
View guidv4.php
<?php
function guidv4()
{
if (function_exists('random_bytes') === true) {
$bytes = random_bytes(16);
} elseif (function_exists('openssl_random_pseudo_bytes') === true) {
$bytes = openssl_random_pseudo_bytes(16);
} elseif (function_exists('mcrypt_create_iv') === true) {
$bytes = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
} elseif (function_exists('com_create_guid') === true) {
@lcherone
lcherone / code.php
Last active Nov 22, 2017
Asymmetric encryption using PHP (the alice and bob story)
View code.php
<?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(),
View c9-lamp-prep.sh
#!/bin/bash
#
# Cloud9 Prep & LAMP Server
# Apache2 (rewrite, headers enabled), PHP7, MariaDB, Git, Composer, nodejs & npm
#
# Set envioroment, for cloud-init
set -e
export DEBIAN_FRONTEND=noninteractive
You can’t perform that action at this time.