Skip to content

Instantly share code, notes, and snippets.

View ethaizone's full-sized avatar
💭
It's same on Gitlab.

Nimit Suwannagate ethaizone

💭
It's same on Gitlab.
View GitHub Profile
@ethaizone
ethaizone / createBlankArray.php
Last active November 28, 2016 09:18
Helper function for create blank array by number of each dimension.
<?php
/**
* Create blank array by number
*
* @param int Number of members in each dimension
* @return array
*/
function createBlankArray()
{
$dimensions = func_get_args();
@ethaizone
ethaizone / sortByArray.php
Last active October 20, 2016 04:14
sortByArray - helper function to sort Array with Array.
<?php
function sortByArray($array, $sortOrder, $options = SORT_REGULAR, $descending = false)
{
// Before first! LOL
// I just extend sortBy in Laravel collection to can use with normal array
// and it will sort data from another array.
// Perfect!!
// Before first. We will add diff array index to last item of sortOrder
@ethaizone
ethaizone / NumberNotation.php
Last active November 2, 2016 05:21
NumberNotation for Eloquent. If you need store data from checkbox and need to query it. This guy is hero. Don't store as stupid json.
<?php
namespace App\Models\Traits;
use Exception;
/**
* This is trait for use with eloquent model only.
* Develop by Nimit Suwannagate <ethaizone@hotmail.com>
* I don't allow to modify anythings in this code.
@ethaizone
ethaizone / reactphp_socket_demo.php
Last active September 27, 2016 09:04
Demo tcp server on PHP.
<?php
// Composer install this package.
// https://github.com/reactphp/socket
// Command support: broadcast, who
require 'vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
@ethaizone
ethaizone / tcp_server.js
Last active September 25, 2016 14:19
Example tcp server write by NodeJS. Just telnet to port in config.
var net = require('net');
// Config
var config = {
server: {
port: 7890
}
};
@ethaizone
ethaizone / step1-comment-as-pseudocode.php
Created September 25, 2016 13:42
How-to make you don't forget to comment your code.
// create array for hold all dogs data
// just loop by get data from getNames()
// getNames() is generator so it's simple loop
// and we just need 5 dogs only
// each dog will name as value
// echo all dogs as json
@ethaizone
ethaizone / get_called_func,php
Last active September 22, 2016 16:56
Get called function in PHP
// This is function for function
// Usage like http://php.net/manual/en/function.get-called-class.php
function get_called_func()
{
$trace = array_slice(debug_backtrace(), -2, 1);
return $trace['function'];
}
@ethaizone
ethaizone / buildMultiDimentionArray.js
Last active September 20, 2016 09:02
Build multi dimentions array from arrays
var data = [];
data.push(['S', 'M', 'L']);
data.push(['RED', 'YELLOW']);
data.push(['IRON', 'COTTON']);
data.push(['ccc', 'ddd']);
// For clone array
Array.prototype.clone = function() {
return this.slice(0);
};
@ethaizone
ethaizone / RelationHelper.php
Last active September 16, 2016 10:46
Eloquent trait act as helper about relation on eloquent.
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Closure;
use Exception;
@ethaizone
ethaizone / chmod_number.php
Last active September 16, 2016 07:43
Create chmod number notation
<?php
/**
* Copyright @ 2016 by Nimit Suwannagate <ethaizone@hotmail.com>. All rights reserved.
*/
// Run this file in cli mode for best view.
// Try to edit this one.
$maxNumber = 500000000000;