Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
ivanhoe011 / ekupi
Created October 21, 2024 08:46
eKupi popust
/**
* Ovaj kod racuna popust u procentima za proizvode na eKupi.hr i dodaje taj podatak na stranu.
*
* Upotreba: Dodajte ovaj kod u Snippets u Chrome DevTools-u, otvorite ekupi.hr stranu sa listom ponuda koja vas zanima,
* desni klik na snippet i onda Run da ga pokrenete.
*/
$('.price-block').each(function () {
const $this = $(this);
const oldPrice = parseInt($this.find('.item-old-price').text().replace(',00 kn', '').replace('.', ''));
const newPrice = parseInt($this.find('.price').text().replace(',00 kn', '').replace('.', ''));
@ivanhoe011
ivanhoe011 / get-filters.js
Created April 10, 2024 07:28
Get all filters from the url's query (following jsonapi.org filters format)
/**
* Get all filters w/ regexp, because UrlSearchParams sux
*
* @param string url
* @return Object
*/
function extractFilters(url) {
return url.matchAll(
/[&?]filter\[([^\]]+)\]=([^&]+)/g
)
@ivanhoe011
ivanhoe011 / json_dd.php
Last active March 29, 2024 12:42
Workaround for Laravel's dd() debugging in new versions of Chrome
<?php
/**
* New versions of Chrome will not render html responses inside of ajax requests that requested json, which
* breaks Laravel's dd() helper method as well as eloquents' ->dd() methods, making it far more complicated
* to see what the generated SQL looks like. This is a simple workaround:
*/
// instead of `dd($foo);`
return response()->json($foo, 500);
@ivanhoe011
ivanhoe011 / html_clipboard.js
Created March 2, 2023 11:59
Get html from clipboard with js
document
// can be any element that knows how to recieve the paste event
.getElementById('someElement')
// add event listener
.addEventListener('paste', e => {
if (! e.clipboardData.types.includes('text/html')) {
// if there's no html on the clipboard ignore it
return;
}
@ivanhoe011
ivanhoe011 / variousCountryListFormats.js
Created March 2, 2023 11:39 — forked from incredimike/variousCountryListFormats.js
List of Countries in various Javascript data structures: Alphabetical country lists & Country data objects.
// Lists of countries with ISO 3166 codes, presented in various formats.
// Last Updated: July 30, 2020
// If you're using PHP, I suggest checking out:
// https://github.com/thephpleague/iso3166
// or Laravel: https://github.com/squirephp/squire
//
// JS developers can check out:
// https://www.npmjs.com/package/iso3166-2-db
//
@ivanhoe011
ivanhoe011 / monitor.sh
Created December 18, 2022 11:51
Monitor bg running script for errors and sound an alarm (on Mac)
tail -f nohup.out | grep -i error | while read line; do say 'Error!'; done
@ivanhoe011
ivanhoe011 / simple.sh
Created December 14, 2022 23:41
Bash script simple template
#!/bin/bash
#
# This script...
#
# Usage: ...
##
set -o pipefail
set -ex
@ivanhoe011
ivanhoe011 / shasum_example.sh
Created December 7, 2022 17:41
Check the sha256 signature without creating a file with the signature, just pass the string
echo "<sha256_signature> *<file_name>" | shasum -a 256 -c
@ivanhoe011
ivanhoe011 / laravel-services.md
Created December 6, 2022 09:32
Laravel services

First class open-source packages

  • Dusk - Browser Testing
  • Envoy - Task Runner
  • Horizon - Queues Manager
  • Jetstream - Frontend Scaffolding
  • Fortify - Headless auth backend
  • Passport - OAuth 2.0
  • Sanctum - Token-based auth
  • Scout - Full-text search
@ivanhoe011
ivanhoe011 / removeEmptyProps.js
Last active October 9, 2024 10:38
Filter out empty properties from the object
/**
* Helper to filter out the empty properties(null, undefined, [], or '') from the given object
*
* @param {{}} obj
* @returns {{}}
*/
const removeEmptyProps = (obj) => {
return Object.keys(obj)
// remove params that are empty
.filter(key => {