Skip to content

Instantly share code, notes, and snippets.

@bgmort
bgmort / useMemoStable.ts
Last active August 9, 2024 22:21
useMemoStable, a useMemo that you can count on to only run once per set of dependency values
import { useRef } from 'react'
/**
* This could also be called `useDerived`. Works like useMemo,
* except it guarantees that it only executes once per change of dependency values,
* which is what `useMemo` is often expected to do, but doesn't guarantee, and doesn't
* do in strict mode.
*
* Differs from `useEffect` in that the value is computed synchronously during render
*/
@bgmort
bgmort / watermark.bash
Created September 16, 2021 23:35
Bash script for watermarking with imagemagick
#!/bin/bash
## This script uses the `convert` command from the imagemagick library to add a watermark to one or more images
WATERMARK= # add your default watermark here
WSIZE="20%"
WPADDING="0"
GRAVITY=SouthEast
OUTDIR=watermarked
DRYRUN=
VERBOSE=
@bgmort
bgmort / parseSignedRequest.js
Last active June 2, 2020 03:09 — forked from cyakimov/gist:1139981
Decode Facebook signed_request with NodeJS
// Fixed an error with character replacement, removed a dependency, included imports, throw errors, and fixed global variables
var crypto = require('crypto');
//remove a dependency on b64url
function atob(str) {
return new Buffer(str, 'base64').toString('binary');
}
//this is not used here, but to leave it out would be like passing the salt without the pepper.
function btoa(str) {
@bgmort
bgmort / embed.html
Last active August 6, 2016 16:42
Simple way to send a whole bunch of texts one at a time from MightyText
Drag this link to your bookmark bar to save as a bookmarklet:
<a href="javascript:var s=document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='https://rawgit.com/bgmort/0fcf5971fe80e2c8ac13737caf9aa9b2/raw/mightytext-masstext.js'; void 0">Mighty Mass Text</a>
@bgmort
bgmort / run_multiple_commands.py
Last active November 18, 2017 12:47
Cleaned up version of code posted at https://forum.sublimetext.com/t/run-multiple-commands-command/6848/35. Added support for repeated commands and example key mappings to move/scroll by ten lines.
# run_multiple_commands.py
import sublime, sublime_plugin
# Takes an array of commands (same as those you'd provide to a key binding) with
# an optional context (defaults to view commands) & runs each command in order.
# Valid contexts are 'text', 'window', and 'app' for running a TextCommand,
# WindowCommands, or ApplicationCommand respectively.
class RunMultipleCommandsCommand(sublime_plugin.TextCommand):
def exec_command(self, command):
if not 'command' in command:
raise Exception('No command name provided.')
<script type="text/javascript">
(function($){
var matches = location.pathname.match(/browse\/([A-Z]+-[0-9]+)/);
if (matches) {
$(document).ready(function() {
/*
* Add diffs to change logs
*/
var script = document.createElement('script');
/**
* converts like objects into a format which will serialize to a more compact JSON string
*/
function listToTable (list, cols){
var table = {};
for (var i = 0, item; item= list[i], i < list.length; i++){
for (var key in item){
if (item.hasOwnProperty(key)){
if (!table[key]) table[key] = [];
table[key][i] = item[key]
@bgmort
bgmort / jira.bulk-edit-subtasks.html
Last active December 11, 2015 05:29
Script providing the functionality discussed at https://jira.atlassian.com/browse/JRA-13079. This script may be added to the page by pasting it into your announcement banner. Provides a link from a JIRA issue page to modify all of the issue's subtasks in bulk. Tested only on JIRA v5.2.1. Thanks to Valentijn Scholten for finding out how to add th…
<script type="text/javascript">
/*
* add an 'edit all' option to issue pages
*/
(function(){
if (location.pathname == '/issues/' && location.hash == '#editall') {
location.href = '/secure/views/bulkedit/BulkEdit1!default.jspa?reset=true'
}
else {
var matches = location.pathname.match(/browse\/([A-Z]+-[0-9]+)/);
@bgmort
bgmort / jquery.trimleft.js
Last active December 10, 2015 20:38
Simple jquery function to trim a line of text with ellipses on left side, like text-overflow: ellipsis clip will in Firefox only. Changes the text permanently, so the amount of text hidden will not change when the window is resized. For this to work, the element you pass in needs to have overflow: hidden and white-space: nowrap; http://stackover…
/**
* Simple jquery function to trim a line of text with ellipses on left side,
* like text-overflow: ellipsis clip will in Firefox only. Changes the text
* permanently, so the amount of text hidden will not change when the window
* is resized.
* For this to work, the element you pass in needs to have overflow: hidden
* and white-space: nowrap;
*
* http://stackoverflow.com/questions/9793473/text-overflow-ellipsis-on-left-side
*/
@bgmort
bgmort / gist:4455742
Created January 4, 2013 20:28
User script providing the functionality discussed at https://jira.atlassian.com/browse/JRA-13079. Provides a link from a JIRA issue page to a search page containing the issue's subtasks, where then can be modified in bulk.
// ==UserScript==
// @name Jira: Edit all sub-tasks
// @description Open subtasks of a story in search so they may all be modified at once
// @match http://jira.your.company.com/browse/*
// ==/UserScript==
(function(){
var matches = location.pathname.match(/[A-Z]+-[0-9]+/),
list, id, item, link;