Skip to content

Instantly share code, notes, and snippets.

<?php
class FileHandler {
/**
* allowable default file types
*/
public $enabled_mimes = array (
'image/png',
'image,jpg', #and what ever you want.
);
<?php
use Illuminate\Database\Migrations\Migration;
class CreatePersRolesTable extends Migration {
/**
* Run the migrations.
*
* @return void
<?php
# start session
session_start();
# if logged in name else make the name FALSE to make an access denied redirect
$name = (empty($_SESSION['username'])?false:$_SESSION['username']);
# Redirect if not logged in
if (!$name)
{
@reshadman
reshadman / idIsValid.js
Created April 11, 2014 16:51
Persian ID Code
function idIsValid(code)
{
var L=code.length;
if(L<8 || parseInt(code,10)==0) return false;
code=('0000'+code).substr(L+4-10);
if(parseInt(code.substr(3,6),10)==0) return false;
var c=parseInt(code.substr(9,1),10);
var s=0;
@reshadman
reshadman / timer.js
Created April 18, 2014 07:34
Javascript Timer
var s=0;
var m=0;
var h=0;
setInterval(function(){elecTimerHandler()},1000);
function elecTimerHandler(){
s++;
if (s>59){
s = 0;
@reshadman
reshadman / pusher.php
Last active August 29, 2015 14:03
Pusher logic
<?php
// I called following loop 5 times
for ($i = 1 ; $i <= 200; $i++)
{
\Queue::push(function ($job){
if (! \Cache::has('start_time')){
\Cache::put('start_time', time() , 1500); // global start time
}
sleep(10); //mock network delay for 25 requests
$id = 25; // number of async request
[2014-06-26 11:46:45] local.INFO: 2703 ms & 301 files included & 355 classes included & "+"4.75mb. [] []
[2014-06-26 11:46:47] local.INFO: 1035 ms & 301 files included & 355 classes included & "+"4.75mb. [] []
[2014-06-26 11:46:50] local.INFO: 978 ms & 301 files included & 355 classes included & "+"4.75mb. [] []
[2014-06-26 11:46:53] local.INFO: 981 ms & 301 files included & 355 classes included & "+"4.75mb. [] []
[2014-06-26 11:46:53] local.INFO: 25 [] []
[2014-06-26 11:46:53] local.INFO: 50 [] []
[2014-06-26 11:46:53] local.INFO: 75 [] []
[2014-06-26 11:46:53] local.INFO: 100 [] []
[2014-06-26 11:46:53] local.INFO: 125 [] []
[2014-06-26 11:46:53] local.INFO: 150 [] []
@reshadman
reshadman / Async.php
Created June 26, 2014 12:25
25 Async request with Guzzle
<?php
public function __construct (\GuzzleHttp\Client $client)
{
$this->client = $client;
}
public function asyncReqs ()
{
$requests = [];
@reshadman
reshadman / Laravel_queue_work_benchmark
Last active August 29, 2015 14:03
بنچمارک کیو پیش فرض لاراول
Machine:
Core i3 CPU 3Ghz
RAM 6GB
Hard Disk , SataII ~7000 rpm
Logic:
Laravel has queue:work in daemon and non-daemon mode, the non-daemon mode takes a job from Queue processes it and then the framework is shut down.
Test logic relies on multi processing + async request using non-daemon mode,
@reshadman
reshadman / Worker.daemon.php
Created June 28, 2014 18:00
Worker long running daemon
<?php
public function daemon($connectionName, $queue = null, $delay = 0, $memory = 128, $sleep = 3, $maxTries = 0)
{
$lastRestart = $this->getTimestampOfLastQueueRestart();
while (true)
{
if ($this->daemonShouldRun())
{
$this->runNextJobForDaemon(