Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
DominikStyp / example_table.sql
Last active August 21, 2021 23:28
SQL: Window Functions advanced example of extracting average (Uber)
USE test;
DROP TABLE IF EXISTS uber_request_logs;
CREATE TABLE IF NOT EXISTS
uber_request_logs (
request_id INT(11),
request_date DATE,
request_status VARCHAR(255),
distance_to_travel FLOAT,
@DominikStyp
DominikStyp / DumpTableDataToSQL.php
Last active October 21, 2021 06:05
Dump Database Table to SQL - Laravel Ready Command (cross platform using Symfony Process)
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class DumpTableDataToSQL extends Command
{
@DominikStyp
DominikStyp / ImportTableWithDataFromSQL.php
Created October 21, 2021 06:08
Import SQL File To MySQL Database: Laravel Ready Command (cross platform using Symfony Process)
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class ImportTableWithDataFromSQL extends Command
{
@DominikStyp
DominikStyp / line_clamp_for_multiple_lines.scss
Created November 8, 2021 15:24
SCSS mixin: Line Clamp for multiple lines (dots for text oferflow)
// https://caniuse.com/?search=line-clamp - way around line-clamp needed
@mixin ellipsis-for-lines($max-lines: 3) {
/* stylelint-disable */
display: -moz-box;
display: -webkit-box;
text-overflow: ellipsis;
-webkit-line-clamp: $max-lines;
-webkit-box-orient: vertical;
-moz-line-clamp: $max-lines;
-moz-box-orient: vertical;
@DominikStyp
DominikStyp / composer.json
Created November 24, 2021 22:57
Laravel composer.json with phpcs phpcbf, post-cmd-scripts etc
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3",
@DominikStyp
DominikStyp / LaravelSqliteBug.php
Created November 29, 2021 10:56
Laravel SQLite Bug
<?php
namespace Tests\Feature;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Tests\CreatesApplication;
class LaravelSqliteBug extends BaseTestCase
@DominikStyp
DominikStyp / where_exists_vs_inner_join.sql
Created December 3, 2021 11:19
SQL: WHERE EXISTS() vs INNER JOIN
-- EXISTS "query_cost": "12.80"
EXPLAIN format=json SELECT * FROM `property_states`
WHERE EXISTS
(SELECT `state` FROM `listing_geos`
WHERE `property_states`.`name` = `listing_geos`.`state`
AND EXISTS (SELECT `id`,
`status` FROM `listings`
WHERE `listing_geos`.`listing_id` = `listings`.`id`
AND `status` = 3)
@DominikStyp
DominikStyp / nested_object_destructuring.js
Last active December 10, 2021 00:13
JavaScript Object Destructuring Nested
// assing level-3 property L3 fast
const obj = {
L1: {
L21: {
L3: 'Hello L3'
},
L22: null
},
L12: 22
};
@DominikStyp
DominikStyp / getDefaultIfPopertyDoesntExist.php
Last active December 16, 2021 11:01
PHP StdClass get default property value if property doesn't exist. Normally this would throw an exception, now it's providing default value.
<?php
/**
* If stdClass property doesn't exist we provide "[NOT_PROVIDED]" string
*
* @param stdClass $settingsObj
* @return stdClass
*/
function getDefaultIfPopertyDoesntExist(\stdClass $stdObj): \stdClass
{
return new class($stdObj) extends \stdClass {
@DominikStyp
DominikStyp / javascript_bind_example.js
Created December 24, 2021 10:18
JavaScript .bind() example: How to pre-configure the callback function
// logs 3 arguments to the console
const testFunc = (a, b, c) => { console.log(`a: ${a}, b: ${b}, c: ${c}`); }
// calls callback with only ONE argument (so TWO are missing)
const giveOnlyC = (callback) => { callback("CCC"); };
// before we send the callback to the `giveOnlyC` we can "pre-configure" its first TWO arguments like this
giveOnlyC( testFunc.bind(null, "AAA", "BBB") ); // a: AAA, b: BBB, c: CCC