Skip to content

Instantly share code, notes, and snippets.

@minedun6
minedun6 / index.js
Created September 23, 2018 07:08
Remember, chaining is a thing in lodash. Just tag a .value() on the end
function getAllActivePostsIds(postsIds) {
return _(posts)
.filter(post => post.is_active)
.map('id')
.value()
}
@minedun6
minedun6 / index.php
Created September 13, 2018 15:05
Flash out the invalid usernames
<?php
$allUserNames = explode(',', $userNames);
$validUserNames = Contact::whereIn('user_name', $allUserNames)
->pluck('user_name')
->toArray();
$invalidUserNames = array_values(array_diff($allUserNames, $validUserNames));
@minedun6
minedun6 / index.php
Created September 1, 2018 16:20
System information Class
<?php
use Carbon\Carbon;
class SystemInformation
{
public function avg()
{
if (is_readable('/proc/loadavg')) {
@minedun6
minedun6 / index.php
Created August 26, 2018 20:51
Check weither array is multi dimensional or not
<?php
private function isMultiDimensionalArray($array) : bool
{
if ( !is_array($array) ) return false;
return count($array) != count( $array, COUNT_RECURSIVE );
}
@minedun6
minedun6 / logslaravel.sh
Created August 19, 2018 10:31 — forked from jakebathman/logslaravel.sh
Tail Laravel logs and filter out the stack traces
tail -f -n 450 storage/logs/laravel*.log \
| grep -i -E \
"^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \
--color
@minedun6
minedun6 / Sluggable.php
Created August 17, 2018 13:19
Create unique slug with #Laravel using the tutorial made by @teamcodecourse
<?php
namespace App\Traits;
trait Sluggable {
public static function bootSluggable() {
static::creating(function ($model) {
$model->slug = (new static)->generateUniqueSlug($model->name);
@minedun6
minedun6 / test.php
Last active August 17, 2018 11:42
Did you know you can compare DateTime objects in PHP using the spaceship operator
<?php
$dates = [
DateTime::createFromFormat('Y-m-d', '2000-02-01'),
DateTime::createFromFormat('Y-m-d', '1994-01-30'),
DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-27 12:03:33'),
DateTime::createFromFormat('Y-m-d', '2006-07-27'),
DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-27 12:04:15'),
];
@minedun6
minedun6 / Address.php
Created August 9, 2018 13:12 — forked from GhazanfarMir/Address.php
Laravel: How to create custom model events
<?php
// App\Address Model
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Observers\AddressObserver; // included our Model Observer
/**
@minedun6
minedun6 / example.php
Created August 9, 2018 13:09 — forked from ozh/example.php
PHP Array pluck function
<?php
$foods = array(
array(
'id' => 4,
'name' => 'Banana',
'color' => 'Yellow',
),
array(
'id' => '5',
'name' => 'Apple',
@minedun6
minedun6 / who_is_my_mummy.sh
Created July 12, 2018 10:05 — forked from joechrysler/who_is_my_mummy.sh
Find the nearest parent branch of the current git branch
#!/usr/bin/env zsh
git show-branch -a \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| sed 's/.*\[\(.*\)\].*/\1/' \
| sed 's/[\^~].*//'
# How it works: