Skip to content

Instantly share code, notes, and snippets.

@shameen
shameen / png-chunks.ts
Last active January 11, 2023 09:29
png: add iTXt chunk metadata (javascript / node.js / typescript)
import fs from "node:fs";
import extract from "png-chunks-extract";
import encode from "png-chunks-encode";
/** Using png-chunks-extract + png-chunks-encode */
function add_itxt_pngchunk(
fileBytes: Uint8Array | Buffer,
value: string,
keyword: string
) {
@shameen
shameen / nvm-upgrade-reinstall.sh
Last active June 14, 2022 15:51
NVM Upgrade/Reinstall latest 2 LTS versions, uninstall everything else. (Doesn't touch system install)
# Please note this script has a chance to break code that depends on a specific version of Node (especially if it is a non-LTS or end-of-life version).
#
# This script will:
# 1. Reinstall and Upgrade the current LTS versions of Node to their latest versions
# 2. Uninstall ALL other nvm versions of Node (except the 'system' version)
# 3. Set the current nvm version to the latest LTS
# output current installed versions of nvm (for reference in case an old version needs installing again)
nvm ls
@shameen
shameen / asyncWithTimeout.ts
Created March 9, 2022 15:56
Typescript promise with timeout
/** Await a promise, or reject after X milliseconds */
const asyncWithTimeout = async <T>(promise: Promise<T>, milliseconds = 10000): Promise<T> => {
//Promise that rejects after X milliseconds
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(`timed out after ${milliseconds} milliseconds`), milliseconds),
);
return await Promise.race([promise, timeoutPromise])
.then((result) => result as T)
.catch((e) => {
@shameen
shameen / mhw-fextralife-full-width.user.js
Last active May 15, 2021 15:27
MHW fextralife wiki full width (userscript)
// ==UserScript==
// @name monsterhunterworld.wiki.fextralife full width
// @namespace http://shameen.info
// @version 0.2
// @description try to take over the world!
// @author shameen
// @match https://monsterhunterworld.wiki.fextralife.com/*
// @icon https://www.google.com/s2/favicons?domain=fextralife.com
// @updateURL https://gist.github.com/shameen/62157b714cb417c258caa01b62d4df1b/raw/c3ada76a6bc62e500cfc4e4461268dcfbfdd8f69/mhw-fextralife-full-width.user.js
// @downloadURL https://gist.github.com/shameen/62157b714cb417c258caa01b62d4df1b/raw/c3ada76a6bc62e500cfc4e4461268dcfbfdd8f69/mhw-fextralife-full-width.user.js
@shameen
shameen / simple-emoji-hash.js
Last active October 27, 2020 16:25 — forked from ikr7/random-emoji.js
given a string, return a single emoji "hash" of it
var emojis = [
'😄','😃','😀','😊','☺','😉','😍','😘','😚','😗','😙','😜','😝','😛','😳','😁','😔','😌','😒','😞','😣','😢','😂','😭','😪','😥','😰','😅','😓','😩','😫','😨','😱','😠','😡','😤','😖','😆','😋','😷','😎','😴','😵','😲','😟','😦','😧','😈','👿','😮','😬','😐','😕','😯','😶','😇','😏','😑','👲','👳','👮','👷','💂','👶','👦','👧','👨','👩','👴','👵','👱','👼','👸','😺','😸','😻','😽','😼','🙀','😿','😹','😾','👹','👺','🙈','🙉','🙊','💀','👽','💩','🔥','✨','🌟','💫','💥','💢','💦','💧','💤','💨','👂','👀','👃','👅','👄','👍','👎','👌','👊','✊','✌','👋','✋','👐','👆','👇','👉','👈','🙌','🙏','☝','👏','💪','🚶','🏃','💃','👫','👪','👬','👭','💏','💑','👯','🙆','🙅','💁','🙋','💆','💇','💅','👰','🙎','🙍','🙇','🎩','👑','👒','👟','👞','👡','👠','👢','👕','👔','👚','👗','🎽','👖','👘','👙','💼','👜','👝','👛','👓','🎀','🌂','💄','💛','💙','💜','💚','❤','💔','💗','💓','💕','💖','💞','💘','💌','💋','💍','💎','👤','👥','💬','👣','💭','🐶','🐺','🐱','🐭','🐹','🐰','🐸','🐯','🐨','🐻','🐷','🐽','🐮','🐗','🐵','🐒','🐴','🐑','🐘','🐼','🐧','🐦','🐤','🐥','🐣','🐔','🐍','🐢','🐛','🐝','🐜','🐞','🐌','🐙','🐚','🐠','🐟','🐬','🐳','🐋','🐄','🐏','🐀','🐃','🐅','🐇','🐉','🐎','🐐','🐓','🐕','🐖','🐁','🐂','🐲','🐡','🐊','🐫','🐪','🐆','🐈','🐩','
@shameen
shameen / jira-classic-backlog-inline-labels.user.js
Last active September 4, 2019 11:38
[Userscript] Classic JIRA backlog: Move labels inline
// ==UserScript==
// @name JIRA classic backlog: Inline labels
// @namespace http://shameen.info
// @version 0.1.1
// @description (Classic JIRA Backlog) Labels shouldnt take up an entire line, this puts them inline on the right of each issue (as the leftmost item)
// @author shameen
// @match https://*.atlassian.net/secure/RapidBoard.jspa?*rapidView=271*
// @downloadUrl https://gist.github.com/shameen/e53581ea7f80c56fdd8942550184af2c/raw/6220806f91df7e827f983406646caba23cb19b16/jira-classic-backlog-inline-labels.user.js
// @grant none
// ==/UserScript==
@shameen
shameen / sanitizeJsonPropertyNames.js
Last active October 11, 2018 15:24
JS: Sanitize JSON data to conform to
/** Make property names conform to javascript property name rules.
* One use case of this is with Kendo UI's Grid, when the column templates are dynamically generated from JSON
*/
sanitizeJsonPropertyNames(arr) {
let _return = [];
for (let i = 0; i < arr.length; i++) {
for (var property in arr[i]) {
//sanitize any property names
let propertyName = property.toString();
propertyName = propertyName.replace(/[\-_]+/g, '_');
@shameen
shameen / quest.html
Created July 2, 2018 16:58
pokemon quest reference for mobile (wrapper for serebii.net pages with links at the top.) http://shameen.info/quest
<!doctype html>
<html>
<head>
<title>pkmn quest</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
@shameen
shameen / monitor-$0-notification-constant.js
Last active April 1, 2021 14:12
dev tools: monitor $0 changes + notify
//This will make a desktop notification EVERY TIME the inspected element $0 changes text.
//in Google Chrome, $0 is the current element inspected in the dev tools.
var initialElem = $0;
var initialText = initialElem.innerText;
var initialVisibility = isVisible(initialElem);
function isVisible(elem) { return !(elem.offsetWidth === 0 && elem.offsetHeight === 0) }
Notification.requestPermission();
clearInterval(x);
var x = setInterval(() => {
var newText = initialElem.innerText;
@shameen
shameen / kendo-treeview-dotted.css
Created April 26, 2018 09:48
Kendo UI TreeView dotted styling (like Windows)
/* Kendo UI TreeView: https://demos.telerik.com/kendo-ui/treeview
* Measurements based on the default "Material" theme as of April 2018, should be easily adjustable for other themes.
*/
.k-treeview .k-item[data-expanded="true"] { overflow:hidden;position:relative; }
.k-treeview .k-item[data-expanded="true"]:before {
content:'';
position:absolute;
top:2em;
bottom:1.2em;