Skip to content

Instantly share code, notes, and snippets.

View tmarshall's full-sized avatar

Tim Marshall tmarshall

View GitHub Profile
@tmarshall
tmarshall / example.js
Created March 8, 2018 00:31
Example JXA script to kick off multiple terminal processes
#!/usr/bin/env osascript -l JavaScript
/*
osascript -l JavaScript <this-file.js>
see https://github.com/JXA-Cookbook/JXA-Cookbook/wiki/
*/
const System = Application('System Events')
const Terminal = Application('Terminal')
[2023-01-01 23:25:00] DELETE /logout 453
[2023-01-11 20:56:00] GET /settings 121
[2023-01-08 18:51:00] POST /dashboard/85 11
[2023-01-12 11:00:00] DELETE /settings 68
[2023-01-12 11:00:00] WARNING Memory usage is high.
[2023-01-12 11:00:00] DETAILS Current usage: 85%, Threshold: 80%
[2023-01-11 20:06:00] GET /profile 278
[2023-01-04 17:19:00] GET /dashboard/12/overview 65
[2023-01-04 00:16:00] GET /home 477
[2023-01-01 04:18:00] POST /settings 434
@tmarshall
tmarshall / lazy-template-literals.js
Last active October 29, 2023 11:21
Lazy javascript template literals
const templatized = (template, vars = {}) => {
const handler = new Function('vars', [
'const tagged = ( ' + Object.keys(vars).join(', ') + ' ) =>',
'`' + template + '`',
'return tagged(...Object.values(vars))'
].join('\n'))
return handler(vars)
}
@tmarshall
tmarshall / aws-sns-example.js
Last active October 30, 2022 06:12
aws-sdk sns example, in Node.js
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: '{AWS_KEY}',
secretAccessKey: '{AWS_SECRET}',
region: '{SNS_REGION}'
});
var sns = new AWS.SNS();
@tmarshall
tmarshall / useUnloadBeacon.js
Last active June 18, 2022 02:39
React hook for unload beacons
/*
see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
```jsx
const MyComponent = ({ children }) => {
// will get fired if the page unloads while the component is mounted
useUnloadBeacon({
url: 'https://api.my.site/route',
payload: () => {
return 'something'
@tmarshall
tmarshall / useHashCode.js
Last active October 15, 2021 21:10
stateful string hash code hook
import { useEffect, useState } from 'react'
/*
takes in a string and returns a hash int code
which can be useful for generating react keys
base on input strings, that may or may not change
const [hashCode, setHashCodeString] = useHashCode()
*/
@tmarshall
tmarshall / useTabTrap.js
Last active April 22, 2021 14:35
Tab trap hook modal (or other) react components.
/*
This hook will trap tabbing within a component.
A common usecase is a Modal, in which you want tabbing to keep focus within the modal.
This assumes that any custom `tabindex` prop is either `0` (should be tabbable, no order preference)
or `-1` (not tabbable, should skip). Anything like `tabIndex={2}` will not get ordered correctly.
It will skip over disabled inputs.
---
@tmarshall
tmarshall / .env
Created December 10, 2020 19:27
streetmerchant ps5 & xbox env config (US)
INCOGNITO=false
LOW_BANDWIDTH=true
PLAY_SOUND="/your/mp3.mp3"
SHOW_ONLY_SERIES="sonyps5c,sonyps5de,xboxss,xboxsx"
STORES="target,walmart,xbox,amazon,antonline,bestbuy,playstation"
@tmarshall
tmarshall / settings.json
Created December 30, 2020 19:03
personal vscode config
{
"editor.tabSize": 2,
"window.zoomLevel": 0,
"editor.snippetSuggestions": "none",
"editor.parameterHints.enabled": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"html.suggest.html5": false,
"editor.hover.enabled": false,
"editor.codeActionsOnSave": null,
"javascript.autoClosingTags": false,
@tmarshall
tmarshall / .vimrc
Created December 16, 2020 21:51
personal .vimrc config
syntax on
colorscheme desert
set encoding=utf8
filetype plugin on
filetype indent on
" Avoid garbled characters in Chinese language windows OS
let $LANG='en'
set langmenu=en