Skip to content

Instantly share code, notes, and snippets.

View stamat's full-sized avatar
💥

Nikola Stamatović stamat

💥
View GitHub Profile
@stamat
stamat / user-agents.json
Last active July 25, 2023 10:50
Numerous navigator.userAgent strings for RegEx testing, scraped from https://deviceatlas.com/blog/list-of-user-agent-string
{
"Android with Client Hints Mobile":"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36",
"Android with Client Hints":"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
"Android with Client Hints Mobile GZIP":"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36,gzip(gfe)",
"Samsung Galaxy S22 5G":"Mozilla/5.0 (Linux; Android 13; SM-S901U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36",
"Samsung Galaxy S22 Ultra 5G":"Mozilla/5.0 (Linux; Android 13; SM-S908U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36",
"Samsung Galaxy S21 5G":"Mozilla/5.0 (Linux; Android 13; SM-G991U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36",
"Samsung Galaxy S21 Ultra 5G":"Mozilla/5.0 (Linux; Android 13; SM-G998U) AppleWebKit/537.36 (KHTML, like Gecko) C
@stamat
stamat / imagebatch.rb
Created September 12, 2022 14:41
Ruby script for batch image resize and optimisation
#!/usr/bin/env ruby
# frozen_string_literal: true
# brew install imagemagick advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush pngquant jonof/kenutils/pngout
# gem install mini_magick image_optim image_optim_pack
# Usage: ./imagebatch.rb [src_dir] [dest_dir] [resize="200x200"] [format="jpg"]
require "mini_magick"
require "image_optim"
@stamat
stamat / package.json
Created March 10, 2022 19:47
rollup nunjucks scss watch livereload
{
"name": "el-camino-rapido",
"version": "1.0.0",
"author": "Nikola Stamatovic <@stamat>",
"homepage": "",
"private": true,
"dependencies": {
"inobounce": "^0.2.0",
"jquery": "^3.5.1",
"remove-focus-outline": "^1.2.1",
@stamat
stamat / wp_menu_tree.php
Last active June 9, 2021 18:45
WordPress submenu tree generator from a list of menu items 🤯
// usage `get_menu_tree('your_menu');`
// PHP 5,7 and 8
function get_menu($menu_name) {
if (( $locations = get_nav_menu_locations()) && isset( $locations[$menu_name])) {
return wp_get_nav_menu_items($locations[$menu_name]);
}
return null;
}
@stamat
stamat / cubic-bezier.scss
Created May 29, 2021 20:27
Cubic Bezier in SCSS... Anyone? I have no idea where I was going with it...
@function cubic-bezier($t,$x1,$y1,$x2,$y2) {
$diff: 1 - $t;
$x: $diff * ( $diff * ($t * $x1) + $t * ($diff * $x1 + $t * $x2)) + $t * ($diff * ( $diff * $x1 + $t * $x2) + $t * ($diff * $x2 + $t));
$y: $diff * ( $diff * ($t * $y1) + $t * ($diff * $y1 + $t * $y2)) + $t * ($diff * ( $diff * $y1 + $t * $y2) + $t * ($diff * $y2 + $t));
@return ($x, $y);
}
@stamat
stamat / country_flag_emojis.txt
Created May 28, 2021 12:15
All country flag emojis separated by a vertical bar for RegExp usage
🇦🇨|🇦🇩|🇦🇪|🇦🇫|🇦🇬|🇦🇮|🇦🇱|🇦🇲|🇦🇴|🇦🇶|🇦🇷|🇦🇸|🇦🇹|🇦🇺|🇦🇼|🇦🇽|🇦🇿|🇧🇦|🇧🇧|🇧🇩|🇧🇪|🇧🇫|🇧🇬|🇧🇭|🇧🇮|🇧🇯|🇧🇱|🇧🇲|🇧🇳|🇧🇴|🇧🇶|🇧🇷|🇧🇸|🇧🇹|🇧🇻|🇧🇼|🇧🇾|🇧🇿|🇨🇦|🇨🇨|🇨🇩|🇨🇫|🇨🇬|🇨🇭|🇨🇮|🇨🇰|🇨🇱|🇨🇲|🇨🇳|🇨🇴|🇨🇵|🇨🇷|🇨🇺|🇨🇻|🇨🇼|🇨🇽|🇨🇾|🇨🇿|🇩🇪|🇩🇬|🇩🇯|🇩🇰|🇩🇲|🇩🇴|🇩🇿|🇪🇦|🇪🇨|🇪🇪|🇪🇬|🇪🇭|🇪🇷|🇪🇸|🇪🇹|🇪🇺|🇫🇮|🇫🇯|🇫🇰|🇫🇲|🇫🇴|🇫🇷|🇬🇦|🇬🇧|🇬🇩|🇬🇪|🇬🇫|🇬🇬|🇬🇭|🇬🇮|🇬🇱|🇬🇲|🇬🇳|🇬🇵|🇬🇶|🇬🇷|🇬🇸|🇬🇹|🇬🇺|🇬🇼|🇬🇾|🇭🇰|🇭🇲|🇭🇳|🇭🇷|🇭🇹|🇭🇺|🇮🇨|🇮🇩|🇮🇪|🇮🇱|🇮🇲|🇮🇳|🇮🇴|🇮🇶|🇮🇷|🇮🇸|🇮🇹|🇯🇪|🇯🇲|🇯🇴|🇯🇵|🇰🇪|🇰🇬|🇰🇭|🇰🇮|🇰🇲|🇰🇳|🇰🇵|🇰🇷|🇰🇼|🇰🇾|🇰🇿|🇱🇦|🇱🇧|🇱🇨|🇱🇮|🇱🇰|🇱🇷|🇱🇸|🇱🇹|🇱🇺|🇱🇻|🇱🇾|🇲🇦|🇲🇨|🇲🇩|🇲🇪|🇲🇫|🇲🇬|🇲🇭|🇲🇰|🇲🇱|🇲🇲|🇲🇳|🇲🇴|🇲🇵|🇲🇶|🇲🇷|🇲🇸|🇲🇹|🇲🇺|🇲🇻|🇲🇼|🇲🇽|🇲🇾|🇲🇿|🇳🇦|🇳🇨|🇳🇪|🇳🇫|🇳🇬|🇳🇮|🇳🇱|🇳🇴|🇳🇵|🇳🇷|🇳🇺|🇳🇿|🇴🇲|🇵🇦|🇵🇪|🇵🇫|🇵🇬|🇵🇭|🇵🇰|🇵🇱|🇵🇲|🇵🇳|🇵🇷|🇵🇸|🇵🇹|🇵🇼|🇵🇾|🇶🇦|🇷🇪|🇷🇴|🇷🇸|🇷🇺|🇷🇼|🇸🇦|🇸🇧|🇸🇨|🇸🇩|🇸🇪|🇸🇬|🇸🇭|🇸🇮|🇸🇯|🇸🇰|🇸🇱|🇸🇲|🇸🇳|🇸🇴|🇸🇷|🇸🇸|🇸🇹|🇸🇻|🇸🇽|🇸🇾|🇸🇿|🇹🇦|🇹🇨|🇹🇩|🇹🇫|🇹🇬|🇹🇭|🇹🇯|🇹🇰|🇹🇱|🇹🇲|🇹🇳|🇹🇴|🇹🇷|🇹🇹|🇹🇻|🇹🇼|🇹🇿|🇺🇦|🇺🇬|🇺🇲|🇺🇳|🇺🇸|🇺🇾|🇺🇿|🇻🇦|🇻🇨|🇻🇪|🇻🇬|🇻🇮|🇻🇳|🇻🇺|🇼🇫|🇼🇸|🇽🇰|🇾🇪|🇾🇹|🇿🇦|🇿🇲|🇿🇼|🏴󠁧󠁢󠁥󠁮󠁧󠁿|🏴󠁧󠁢󠁳󠁣󠁴󠁿|🏴󠁧󠁢󠁷󠁬󠁳󠁿|🏴󠁵󠁳󠁴󠁸󠁿
@stamat
stamat / waiter.js
Created December 24, 2019 21:02
Simple recursive function that waits for DOM changes, used to wait for embedded-JS generated third party code, when no hook apparent or available
function waiter(selector, callback, timeout) {
var elem = document.querySelectorAll(selector);
if (!elem.length) {
if (timeout === undefined) {
timeout = 100;
}
setTimeout(function(){
waiter(selector, callback, timeout);
@stamat
stamat / slug.js
Created August 16, 2019 23:08
Wordpress like simple sanitize_title for javascript. Not checking for accents, since it is a slow process.
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
function slug(s) {
s = s.toLowerCase().trim();
s = s.replace(/[^a-z0-9\s_-]/ig, '');
return s.replace(/[\s\uFEFF\xA0]+/ig, '-');
@stamat
stamat / _neat.scss
Created July 6, 2018 12:27
Neat 3.0.0 in one SASS file for Shopify theme dev
@charset "UTF-8";
// Neat 3.0.0
// http://neat.bourbon.io
// Copyright 2012 thoughtbot, inc.
// MIT License
/// This variable is a sass map that overrides Neat's default grid settings.
/// Use this to define your project's grid properties including gutters and
/// total column count.
///
@stamat
stamat / itetate_arguments.js
Last active December 31, 2015 20:59
A simple snippet for iterating arguments
var eachArg = function(args, fn, start_from, end_where) {
var i = start_from || 0;
while (i < args.length) {
if (end_where !== undefined && i === end_where)
return i;
if (fn !== undefined)
fn(i, args[i]);
i++;
}
return i;