Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
ivanhoe011 / ekupi
Last active February 12, 2025 14:18
eKupi popust
/**
* This code snippet calculates the discount % on eKupi.hr and injects the info for each listing.
*
* Usage: Paste the code int Snippets in Chrome DevTools, open ekupi.hr page of interest,
* right-click the Snipper and choose Run.
*/
$('.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 / 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 => {
@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 / cleanup.php
Last active March 12, 2023 13:12
Proper way to remove all metadata from an image
<?php
$img = new Imagick($img);
// code by Max Eremin http://php.net/manual/en/imagick.stripimage.php#120380
// we need to keep the ICC profiles
$profiles = $img->getImageProfiles('icc', true);
// but remove everything else
@ivanhoe011
ivanhoe011 / .eslintrc.json
Created July 21, 2018 10:41
ESLint setup for react, jsx, es2018, class properties, etc...
{
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"eslint-config-prettier"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
@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 / make_thumbs.php
Last active February 2, 2023 02:15
Convert .ai, .psd, .jpg, .png, .gif into thumbnails
<?php
/**
* Convert
* http://stackoverflow.com/questions/12516842/convert-psd-and-ai-to-png-jpg-with-imagick
* @param string $dir Directory to save to.
* @param string $tmpName The name to name the file excluding the extension.
* @param string $fileType
* @param string $size Large or small.
*/
@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