Skip to content

Instantly share code, notes, and snippets.

@ricsam
ricsam / README.md
Last active November 8, 2023 10:56
Global pull credentials in kubernetes

Installation on ubuntu:

  1. Save bash script to /usr/local/bin/update-service-accounts.sh
  2. Save systemd file to /etc/systemd/system/update-service-accounts.service

Enable the service:

# Reload systemd to pick up the new service
sudo systemctl daemon-reload
@ricsam
ricsam / .prettierignore
Last active November 1, 2022 10:38
Default .prettierignore file when using prettier with rush
#-------------------------------------------------------------------------------------------------------------------
# Keep this section in sync with .gitignore
#-------------------------------------------------------------------------------------------------------------------
# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
@ricsam
ricsam / topt.js
Created April 14, 2020 11:54
Get google authenticator opt code using node.js, usage topt.js [SECRET_CODE]
const crypto = require('crypto');
const decToHex = (dec) => dec.toString(16);
const hexToDec = (hex) => parseInt(hex, 16);
const base32chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
const base32ToHex = (base32) => {
const bits = base32
.split('')
.map((char) => {
@ricsam
ricsam / get-filename.code-snippets
Created February 20, 2020 10:44
place in .vscode dir
{
"pure": {
"scope": "javascript,typescript,javascriptreact,typescriptreact",
"prefix": "filename",
"body": [
"${1:$TM_FILENAME_BASE}",
],
"description": "Get current filename"
}
}
@ricsam
ricsam / machine.js
Created January 29, 2020 20:03
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@ricsam
ricsam / machine.js
Last active January 5, 2020 17:06
Generated by XState Viz: https://xstate.js.org/viz
const cc = (prefix, suffix) => {
return prefix + suffix[0].toUpperCase() + suffix.slice(1);
};
const makeStateNode = (events) => ({
on: { ...events, logout: 'logout' },
});
const makeError = (next) => {
const useSafeState = (initialState) => {
const [state, unsafeSetState] = useState(initialState);
const unmounted = useRef(false);
useEffect(
() => () => {
unmounted.current = true;
},
[]
const useResponsiveCanvas = (cb) => {
const [width, setWidth] = useState(false);
const [measureEl, setMeasureEl] = useState(null);
const [canvasEl, setCanvasEl] = useState(null);
const draw = useCallback(() => {
if (!canvasEl || !measureEl) {
return;
}
const w = measureEl.offsetWidth;
const useResize = (cb) => {
useEffect(() => {
window.addEventListener('resize', cb);
return () => {
window.removeEventListener('resize', cb);
};
}, [cb]);
};
const useResponsiveClientRect = () => {
const [rect, setRect] = useState(null);
const ref = useRef();
const measure = useMemo(
() => () => {
if (ref.current) {
setRect(ref.current.getBoundingClientRect());
}
},
[]