Skip to content

Instantly share code, notes, and snippets.

@reshadman
reshadman / Loop.java
Created May 3, 2015 17:15
Simple loop in programming languages -- for permance benchmarking of a WHILE LOOP --
public class Loop {
public static void main(String[] args)
{
Integer total = 500000000;
Integer chunk = 50000000;
Integer i = 0;
[{
"_id" : ObjectId("550d2255d2ea07ae148b456d"),
"comments" : [
{
"_id" : ObjectId("550d2255d2ea07ae148b4567"),
"title" : "salam comment 1",
"body" : "salam comment matn 1",
"cid" : 1
},
{
<?php namespace Bigsinoos\Helpers;
class TreeFilter {
/**
* Get only some variables of a tow-level nested array
*
* @param $filterable
* @param array $keep
* @return array
*/
array(2) {
[0] array(7) {
["phone_number"] 91212345678
["creator_id"] 53
["description"] "number 1"
["priority"] 0
["shared"] true
["phones"] array(1) {
["phone_number"] 91212345678
}
<?php
foreach($collection as $key => $item){
if(is_array($item)){
foreach($item as $tree => $treeItem){
if($tree != 'phones'){
unset($item[$tree])
}
}
}
@reshadman
reshadman / muli.php
Created September 8, 2014 07:41
Multiple binding of a class
<?php
class Session {
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
}
class RedisStorage implments StorageInterface {}
@reshadman
reshadman / job.php
Created August 25, 2014 07:19
JobManagerWrapper.php
<?php
class JobManagerWrapper {
public function __call($method, $args)
{
$instance = App::make('JobManager');
return call_user_func_array([$instance, $job], $args);
}
}
@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(
@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 / 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 = [];