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
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
cache.properties
build
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
cache.properties
build
@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();
@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 / 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 / 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" }
];
<?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 / queryListDatesBetween.sql
Last active October 24, 2019 04:31
Get list of dates between two dates in mysql select query
select * from
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where selected_date between '2018-10-29' and '2018-11-01';
@ufhy
ufhy / webpack.mix.js
Created February 10, 2020 12:20
Laravel mix configuration using vuetify
const mix = require('laravel-mix');
const path = require("path");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const _root = path.resolve(__dirname, ".");
const rootPath = function(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
};