Skip to content

Instantly share code, notes, and snippets.

@hdodov
hdodov / iframechange.js
Last active September 15, 2023 15:35
HTML iframe URL change listener for tracking when a new iframe page starts to load
function iframeURLChange(iframe, callback) {
var lastDispatched = null;
var dispatchChange = function () {
var newHref = iframe.contentWindow.location.href;
if (newHref !== lastDispatched) {
callback(newHref);
lastDispatched = newHref;
}
@hdodov
hdodov / .zshrc
Last active September 13, 2023 09:15
# Enable git autocompletions
autoload -Uz compinit && compinit
# Change terminal prompt to "$directory ($branch)"
autoload -Uz vcs_info
zstyle ':vcs_info:git:*' formats ' (%b)'
precmd () { vcs_info }
setopt prompt_subst
PS1='%F{yellow}%1~%f%F{cyan}$vcs_info_msg_0_%f $ '
@hdodov
hdodov / _repl.ts
Last active February 20, 2023 15:17
Payload CMS playground script for running code in a REPL fashion.
// NOTE: This file must be in the `src` folder, i.e. `src/repl.ts`.
/**
* Playground script that can be used in a REPL fashion.
* Just `npm run repl` and Payload will run in a minimal, local API mode.
* @see https://payloadcms.com/docs/local-api/overview#local-api
*/
import payload from "payload";
import dotenv from "dotenv";
@hdodov
hdodov / replace-variables-hook.ts
Last active January 16, 2023 06:33
Payload CMS dynamic variables with `{{` and `}}`. You can also add modifiers, e.g. `{{ my_var:millions }}` and divide the value by 1e6.
import payload from "payload";
import { CollectionAfterReadHook } from "payload/types";
import { Variable } from "../payload-types";
const pattern = /{{\s*(.*?)\s*}}/g;
const modifiers: { [key: string]: (input: string) => string } = {
millions: (value) => Math.floor(parseInt(value) / 1e6).toString(),
};
/**
@hdodov
hdodov / cordova-permission-removal.md
Last active July 15, 2021 10:00
How to completely remove an Android permission from Cordova app.

In this example, I'll show how to remove the RECORD_AUDIO permission.


  1. Navigate to the plugins directory in your Cordova folder.

  2. Open the plugin.xml file of each plugin and search for something like:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
@hdodov
hdodov / superhosting-ssh.md
Created November 20, 2020 17:11
SuperHosting Kirby Git SSH setup instructions
  1. Open a terminal from cPanel

  2. Use ssh-keygen to generate a key (with no passphrase)

    Note: You can't use SuperHosting's GUI SSH key manager because it demands a passphrase, and that's not an option since kirby-git can't fill it in.

  3. Run cat ~/.ssh/id_rsa.pub to print the public key and copy it

  4. Go to GitHub and paste the public key (in the Deploy Keys settings panel)

  5. Test with ssh -T -p 443 git@ssh.github.com

    Expected output:

@hdodov
hdodov / google-sheets-append-rows.php
Created January 9, 2020 12:40
Script that appends rows to a spreadsheet via the Google Sheets API.
<?php
require __DIR__ . '/vendor/autoload.php';
$creds = 'credentials.json';
$sheedId = '1IMwiyCa1gCfh1lacyzZqFrYFsqCe-hOSRlaHIc2gFDw';
$range = 'Sheet1';
$client = new Google_Client();
$client->setAuthConfigFile($creds);
$client->useApplicationDefaultCredentials();
basicConstraints=CA:FALSE
keyUsage=digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
authorityKeyIdentifier=keyid,issuer
subjectAltName = @alt_names
[alt_names]
DNS.1=localhost
@hdodov
hdodov / _media-smart.scss
Last active December 6, 2018 20:03
Flexible Sass media queries with no hardcoding. Specify your breakpoints and you'll have mixins for media queries that are smaller, larger or inside the device ranges. Mobile first (like Bootstrap).
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
$screens: (
"xs": 0px,
"sm": 768px,
"md": 992px,
"lg": 1200px
@hdodov
hdodov / mixin-to-rule.scss
Created January 16, 2018 07:42
Regex to convert all SCSS mixins to simple CSS rules for transitioning from Bourbon to Autoprefixer.
// Find (add properties as needed):
@include\s*(animation|appearance|transform|transition|display|align-items|justify-content|flex-flow|flex|backface-visibility|user-select)\(([^;]+)\);
// Replace:
$1: $2;
// ----------------------------------
// Transforms this:
@include display(flex);