Skip to content

Instantly share code, notes, and snippets.

View ufhy's full-sized avatar
🏠
Working from home

ufhy

🏠
Working from home
View GitHub Profile
<?php defined('BASEPATH') OR exit('No direct script access allowed');
if ( ! function_exists('timespan'))
{
/**
* Timespan
*
* Returns a span of seconds in this format:
* 10 days 14 hours 36 minutes 47 seconds
*
@ufhy
ufhy / shortsNumber.js
Created April 22, 2019 14:02
Format a number as 2.5K if a thousand or more, otherwise 900
function nFormatter(num, digits) {
var si = [
{ value: 1, symbol: "" },
{ value: 1E3, symbol: "k" },
{ value: 1E6, symbol: "M" },
{ value: 1E9, symbol: "G" },
{ value: 1E12, symbol: "T" },
{ value: 1E15, symbol: "P" },
{ value: 1E18, symbol: "E" }
];
@ufhy
ufhy / shortsNumber.js
Created April 22, 2019 14:02
Format a number as 2.5K if a thousand or more, otherwise 900
function nFormatter(num, digits) {
var si = [
{ value: 1, symbol: "" },
{ value: 1E3, symbol: "k" },
{ value: 1E6, symbol: "M" },
{ value: 1E9, symbol: "G" },
{ value: 1E12, symbol: "T" },
{ value: 1E15, symbol: "P" },
{ value: 1E18, symbol: "E" }
];
@ufhy
ufhy / hierarchy.js
Created March 16, 2019 16:29
Find all the parents of each element (hierarchy)
var tree = [
{ "roleName" : "Humans", "roleId" : "role2", "children" : []},
{ "roleName" : "Trees", "roleId" : "role2", "children" : []},
{ "roleName" : "Animals", "roleId" : "role2", "children" : [
{ "roleName" : "Cats", "roleId" : "role11", "children" : []},
{ "roleName" : "Lions", "roleId" : "role11", "children" : []},
{ "roleName" : "Dogs", "roleId" : "role11", "children" : [
{ "roleName" : "Terrier", "roleId" : "role11", "children" : []},
{ "roleName" : "Bulldog", "roleId" : "role11", "children" : []},
{ "roleName" : "Cocker", "roleId" : "role11", "children" : []},
@ufhy
ufhy / benchmark.php
Created September 18, 2018 00:33
Snippet Code To Benchmark Your PHP Script
<?php
$start = microtime(true);
// Script you want to test here
usleep(200000); // sleep 2 seconds
$end = microtime(true);
$r = round($end - $start,4);
echo '<strong>Execution Time</strong>: '.$r.' seconds<br />';
@ufhy
ufhy / generator.php
Created September 12, 2018 12:41 — forked from tawfekov/generator.php
Doctrine2 Generate Entities form Existing Database
<?php
include '../vendor/autoload.php';
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
// config
$config = new \Doctrine\ORM\Configuration();
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
cache.properties
build
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
cache.properties
build