Skip to content

Instantly share code, notes, and snippets.

@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 / 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 {}
<?php
foreach($collection as $key => $item){
if(is_array($item)){
foreach($item as $tree => $treeItem){
if($tree != 'phones'){
unset($item[$tree])
}
}
}
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 namespace Bigsinoos\Helpers;
class TreeFilter {
/**
* Get only some variables of a tow-level nested array
*
* @param $filterable
* @param array $keep
* @return array
*/
[{
"_id" : ObjectId("550d2255d2ea07ae148b456d"),
"comments" : [
{
"_id" : ObjectId("550d2255d2ea07ae148b4567"),
"title" : "salam comment 1",
"body" : "salam comment matn 1",
"cid" : 1
},
{
@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;
@reshadman
reshadman / action.js
Last active November 1, 2015 11:57
Processing Laravel jobs from node.
'use strict';
var redis = require('redis');
var LaravelJob = require('./index');
// Create laravel job instance
var job = new LaravelJob({});
// Set handlers on the job
job.registerHandler("Jobinja\\Jobs\\ExampleJob", function(job, payload) {
console.log(payload);
<?php
require_once 'recipe/common.php';
// A deploy script for for deployer.org used at Jobinja.ir
// The script creates a folder for each one of your releases
// and makes them zero downtime deploys, this is tuned for laravel
// but the logic can be used for anything which needed transactional folder
// based changes.
// As some of the npm packages are banned in our server ISP we use
// a combination of shadowsocks and polipo(for reversing https and socks)
<?php
class UserController {
public function postCreate(UserCreatorService $userCreatorService, Request $request)
{
$creationNeeds = new CreationValueObject;
$creationNeeds->username = $request->username;
$creationNeeds->password = $request->password;
$creationNeeds->email = $request->email;