Skip to content

Instantly share code, notes, and snippets.

mhipo1364 / sort.php
Created Sep 10, 2018
Sort array of objects using usort in php
View sort.php
public static function sortByPriceAscending($jsonString)
$props = ['price', 'name'];
$products = json_decode($jsonString);
usort($products, function ($productOne, $productTwo) use ($props) {
if ($productOne->{$props[0]} == $productTwo->{$props[0]}) {
return $productOne->{$props[1]} < $productTwo->{$props[1]} ? -1 : 1;
mhipo1364 / Sluggable.php
Last active Sep 9, 2018
Persian slug trait for PHP
View Sluggable.php
namespace App\Traits;
use Illuminate\Support\Str;
* Trait Sluggable
* @package App\Traits
mhipo1364 /
Created Aug 3, 2016
Re-Generate(Merge) Migration Files In Django

Re-Generate Migration

To merge exist migration files into one file:

  • Remove django_migration records table (manually)
  • Remove all migration files
  • run python migrate --fake command
  • run python makemigrations command
  • run python migrate --fake-initial command
  • run python migrate contenttypes command
mhipo1364 /
Created Oct 27, 2015
This static method generate proper url via given parameters
def _generate_url(**kwrgs):
This static method generate proper url via given parameters
:param kwrgs:
:return: string
url = settings['CUSTOM_BASE_URL'] + '/{}?'.format(kwrgs.pop('uri'))
for idx, (key, value) in enumerate(kwrgs.items()):
if idx:
mhipo1364 /
Last active Aug 29, 2015
How to send parameters to method which is called by call_later in asyncio loop
from functools import partial
import datetime
function_handler = partial(show_time, data=2)
loop = asyncio.get_event_loop()
loop.call_later(30, function_handler)
def show_time(data):
You can’t perform that action at this time.