Skip to content

Instantly share code, notes, and snippets.


Matt Komarnicki mattkomarnicki

View GitHub Profile
View Using pluck() method on nested

Using pluck() method on nested relationships.

Normally in Laravel querying a given model with its relationships allows you to use dot notation to reach nested ones.

Relationship definitions

For example imagine we have 3 models - Configuration, EngineType and CarBrand. For the sake of simplicity the linkage goes as follows:

  • Configuration::class belongs to an EngineType::class
  • EngineType::class belongs to a CarBrand::class
exiftool -XMP:GPSLatitude=1.288249 -XMP:GPSLongitude=103.851536 -P -overwrite_original A7304765.ARW
// Reload metadata in Capture One
// -overwrite_original will prevent from making extra copy of the target file
View camel_case_to_human.php
private function camelCaseToHuman(string $input): string
$result = preg_split('/(^[^A-Z]+|[A-Z][^A-Z]+)/', $input, -1, PREG_SPLIT_NO_EMPTY| PREG_SPLIT_DELIM_CAPTURE);
return ucfirst(implode(' ', $result));
View phpbb_posts_per_month.sql
SELECT YEAR(FROM_UNIXTIME(post_time)) as `year`, LPAD(MONTH(FROM_UNIXTIME(post_time)), 2, 0) as `month`, COUNT(post_id) as count FROM phpbb3_posts
GROUP BY `year`, `month`
ORDER BY `year`, `month` ASC
View gist:878bfbe9f34583c180346726ac1c149b
# There was a day where I have too many color schemes in iTerm2 and I want to remove them all.
# iTerm2 doesn't have "bulk remove" and it was literally painful to delete them one-by-one.
# iTerm2 save it's preference in ~/Library/Preferences/com.googlecode.iterm2.plist in a binary format
# What you need to do is basically copy that somewhere, convert to xml and remove color schemes in the xml files.
$ cd /tmp/
$ cp ~/Library/Preferences/com.googlecode.iterm2.plist .
$ plutil -convert xml1 com.googlecode.iterm2.plist
$ vi com.googlecode.iterm2.plist
# 1) Save below script as a file with *.sh extension
#! /bin/bash
echo Cleaning Zoom…
echo Cleaning Application Cached Files…
sudo rm -rf ~/Library/Application\ Support/
echo Cleaning Application…
sudo rm -rf /Applications/
sudo rm -rf ~/Applications/
mattkomarnicki /
Created Mar 17, 2019 — forked from dergachev/
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF


To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

View events.js
// MIT licensed, Written by Abdul Khan and Alexey Novak, 2014
// version 0.1.3
var utils = utils || {};
// Publish/Subscribe pattern adapted from
(function() {
utils.Events = function() {
mattkomarnicki / format_number_in_k_notation.php
Last active Jun 28, 2019
Formats given integer into short version with a suffix. For example "1500" will become "1K+".
View format_number_in_k_notation.php
if (!function_exists('format_number_in_k_notation')) {
function format_number_in_k_notation(int $number): string
$suffixByNumber = function () use ($number) {
if ($number < 1000) {
return sprintf('%d', $number);
View redundant_else_redundant_if.php
// example 1 (lame)
public function isAdmin(): bool
if ($this->permission->canAccess('dashboard')) {
return true;
} else {
return false;