Skip to content

Instantly share code, notes, and snippets.

View gladchinda's full-sized avatar

Glad Chinda gladchinda

View GitHub Profile
@gladchinda
gladchinda / keygen-test.php
Last active April 18, 2018 08:10
Code to test PHP Keygen package installation by just generating some random keys.
<?php
require __DIR__ . '/vendor/autoload.php';
use Keygen\Keygen;
$id_12 = Keygen::numeric(12)->generate();
$id_16 = Keygen::numeric()->generate();
$alnum = Keygen::alphanum(15)->generate();
$token = Keygen::token(28)->generate();
@gladchinda
gladchinda / keygen-transformations-test.php
Last active April 18, 2018 08:10
Code to test how to use Keygen transformations.
<?php
require __DIR__ . '/vendor/autoload.php';
use Keygen\Keygen;
$splitString = function($key) {
return join('-', str_split($key, 4));
};
$shortHash20 = function($key) {
@gladchinda
gladchinda / keygen-affixes-test.php
Created January 5, 2018 10:13
Code to test how to use affixes with the Keygen package.
<?php
require __DIR__ . '/vendor/autoload.php';
use Keygen\Keygen;
// Prefix (inclusive enabled)
echo Keygen::numeric(12)->prefix('TM-')->generate(); // e.g TM-218624395
// Prefix (inclusive disabled)
echo Keygen::numeric(12)->prefix('TM-')->generate(true); // e.g TM-382104609735
@gladchinda
gladchinda / add-function-es5.js
Last active January 11, 2018 19:29
Solution to sum function challenge. Here are some examples: ( add(2) == 2 ) ( add(1)(2)(3) == 6 )
var add = function add() {
var args = Array.prototype.slice.call(arguments);
var fn = Function.prototype.bind.apply(add, [null].concat(args));
fn.valueOf = function() {
return args.reduce(function(a, b) {
return a + parseInt(b);
}, 0);
};
return fn;
}
const student = {
name: 'John Doe',
age: 16,
scores: {
maths: 74,
english: 63,
science: 85
}
};
function displaySummary({ name, scores: { maths = 0, english = 0, science = 0 } }) {
console.log('Hello, ' + name);
console.log('Your Maths score is ' + maths);
console.log('Your English score is ' + english);
console.log('Your Science score is ' + science);
}
const student = {
firstname: 'Glad',
lastname: 'Chinda',
country: 'Nigeria'
};
// Object Destructuring
const { firstname, lastname, country } = student;
console.log(firstname, lastname, country); // Glad Chinda Nigeria
// Initialize local variables
let country = 'Canada';
let firstname = 'John';
let lastname = 'Doe';
const student = {
firstname: 'Glad',
lastname: 'Chinda',
country: 'Nigeria'
};
const person = {
name: 'John Doe',
country: 'Canada'
};
// Assign default value of 25 to age if undefined
const { name, country, age = 25 } = person;
// Here I am using ES6 template literals
console.log(`I am ${name} from ${country} and I am ${age} years old.`);
const person = {
name: 'John Doe',
country: 'Canada'
};
// Assign default value of 25 to years if age key is undefined
const { name: fullname, country: place, age: years = 25 } = person;
// Here I am using ES6 template literals
console.log(`I am ${fullname} from ${place} and I am ${years} years old.`);