Skip to content

Instantly share code, notes, and snippets.

Moe Far mhipo1364

Block or report user

Report or block mhipo1364

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mhipo1364
mhipo1364 / sort.php
Created Sep 10, 2018
Sort array of objects using usort in php
View sort.php
<?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
mhipo1364 / Sluggable.php
Last active Sep 9, 2018
Persian slug trait for PHP
View Sluggable.php
<?php
namespace App\Traits;
use Illuminate\Support\Str;
/**
* Trait Sluggable
* @package App\Traits
*/
@mhipo1364
mhipo1364 / merge_migration.md
Created Aug 3, 2016
Re-Generate(Merge) Migration Files In Django
View merge_migration.md

Re-Generate Migration

To merge exist migration files into one file:

  • Remove django_migration records table (manually)
  • Remove all migration files
  • run python manage.py migrate --fake command
  • run python manage.py makemigrations command
  • run python manage.py migrate --fake-initial command
  • run python manage.py migrate contenttypes command
@mhipo1364
mhipo1364 / create_url.py
Created Oct 27, 2015
This static method generate proper url via given parameters
View create_url.py
@staticmethod
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
mhipo1364 / __main__.py
Last active Aug 29, 2015
How to send parameters to method which is called by call_later in asyncio loop
View __main__.py
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):
print(datetime.now())
print(data)
You can’t perform that action at this time.