Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
DominikStyp / laravel-trans-example-in-raw-html.php
Created December 7, 2016 09:58
Przykład na modyfikacje funkcji trans()
<?php
function trans($key){
static $translates = [
'months_1' => 'Styczeń',
'months_2' => 'Luty',
'months_3' => 'Marzec',
'months_4' => 'Kwiecień',
'months_5' => 'Maj',
'months_6' => 'Czerwiec',
'months_7' => 'Lipiec',
@DominikStyp
DominikStyp / popover-x-hide-on-body-click.js
Created March 8, 2018 11:54
Popover-X hide on body click, but not on popover click.
$('body').on('click', function (e) {
var isPopoverClicked = ($(e.target).parents('.popover-x').length > 0);
var isButtonPopoverClicked = $(e.target).is('.publicKeyPopoverButton');
if(isPopoverClicked || isButtonPopoverClicked){
return true;
}
$('.popover-x').popoverX('hide');
});
@DominikStyp
DominikStyp / re-init-popovers-when-pjax-reloads-gridview.js
Created March 8, 2018 11:56
Re-init popoovers when Pjax reloads GridView
function reInintPopovers(){
var $btns = $("[data-toggle='popover-x']");
if ($btns.length) {
$btns.popoverButton();
}
}
$(document).on('pjax:end', function() {
reInintPopovers();
});
@DominikStyp
DominikStyp / trigger-form-input-change-event-on-keyup-with-timeout.js
Created March 8, 2018 11:58
Trigger form input change event after timeout (when user stops writing in the field for X miliseconds)
document._keyPushTimeoutId = 0;
$(document).on('keyup', 'input.form-control', function(){
var element = $(this);
window.clearTimeout(document._keyPushTimeoutId);
document._keyPushTimeoutId = setTimeout(function(){
element.change();
}, 500);
});
@DominikStyp
DominikStyp / laravel_docs_dark_theme.css
Created March 5, 2021 19:53
Stylish (Chrome Extension) Laravel Docs Dark Theme
body {
color: #000;
background: #525252 url("/assets/img/cloud-bar.png") repeat-x;
}
.docs_main p {
color:#000;
}
aside div {
background: #c5c5c5;
}
@DominikStyp
DominikStyp / example_table.sql
Last active August 10, 2021 22:54
SQL Window Functions (MariaDB), PARTITION BY
DROP TABLE IF EXISTS `test`.`employee`;
CREATE TABLE `test`.`employee` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`manager_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`));
INSERT INTO `test`.`employee` (`name`, `manager_id`) VALUES ('Dev1', '10');
INSERT INTO `test`.`employee` (`name`, `manager_id`) VALUES ('Dev2', '10');
@DominikStyp
DominikStyp / example_table.sql
Last active August 11, 2021 21:12
SQL Window Functions: Find next id for every row in result set ("holes" in ids included)
USE test;
DROP TABLE IF EXISTS `employee`;
CREATE TABLE `employee` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`manager_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`));
@DominikStyp
DominikStyp / expected_result.csv
Last active August 15, 2021 21:10
SQL: Selecting data from JSON_TABLE()
name color price
Laptop black 11000.00
Jeans blue NULL
@DominikStyp
DominikStyp / example_table.sql
Created August 16, 2021 20:50
SQL GROUP BY WITH ROLLUP: Grouping by multiple columns and rolling up to one
CREATE TABLE test (
id INT PRIMARY KEY AUTO_INCREMENT,
year SMALLINT,
month TINYINT,
revenue INT
);
INSERT INTO test (year, month, revenue) VALUES
(2020, 01, 900),
(2020, 02, 1500),
@DominikStyp
DominikStyp / example_table.sql
Created August 16, 2021 21:21
SQL GROUP BY WITH CONDITIONAL SUM (CASE WHEN)
CREATE TABLE test (
id INT PRIMARY KEY AUTO_INCREMENT,
year SMALLINT,
month TINYINT,
day TINYINT,
revenue INT
);
INSERT INTO test (year, month, day, revenue) VALUES
(2020, 01, 31, 9000),