Skip to content

Instantly share code, notes, and snippets.

{
"keyMappings": "# Insert your preferred key mappings here.\nmap e scrollPageUp",
"linkHintCharacters": "asdfqwerzxcv",
"regexFindMode": true,
"smoothScroll": false,
"settingsVersion": "2.1.2",
"exclusionRules": [
{
"passKeys": "",
"pattern": "https?://mail.google.com/*"
@pirey
pirey / helpers.ts
Created December 28, 2023 11:05
some helper functions
function randomBoolean() {
return Math.random() < 0.5;
}
function chunkArray<T>(array: T[], chunkSize: number): T[][] {
return Array.from(
{ length: Math.ceil(array.length / chunkSize) },
(_, index) => array.slice(index * chunkSize, (index + 1) * chunkSize),
);
}
@pirey
pirey / withMeasure.ts
Created December 28, 2023 10:57
print simple perf measurement
async function withMeasure<T>(label: string = 'Measurement', fn: () => Promise<T>) {
function bytes2MB(bytes: number): number {
return bytes / (1024 * 1024)
}
const pstart = performance.now()
const mstart = process.memoryUsage().heapUsed
const result = await fn()
@pirey
pirey / tmux-cheatsheet.md
Created October 31, 2023 00:46
tmux cheatsheet

<prefix>-space change layout

<prefix>-} <prefix>-{ move pane

-; move between panes

@pirey
pirey / multilinecontent.jsx
Last active October 28, 2023 10:58
react display multiline text content
function Comp({ content }) {
return content.split('\r\n').map((line, i) =>
<p key={i}>{line.length ? line : <br />}</p>)
}
@pirey
pirey / notes.md
Created October 27, 2023 16:56
Personal laravel notes

laravel version: 10

authorization

policy

  • -> authorization logic for model
  • -> auto detected if following naming convention, User -> UserPolicy
  • $request->user()->can('update', $post)
  • $request->user()->cannot('create', Post::class)
  • $this-&gt;authorize('update', $post);
@pirey
pirey / useOutsideAlerter.js
Created October 25, 2023 03:57
event handler outside element
function useOutsideAlerter(ref, eventType, callback, childSelector) {
useEffect(() => {
function handler(event) {
if (!ref.current) return;
const clickedOutside = childSelector
? !Array.from(ref.current.querySelectorAll(childSelector)).some(
(node) => node.contains(event.target),
)
: !ref.current.contains(event.target);
set -g default-terminal "screen-256color"
set-option -sa terminal-overrides ",xterm-256color:RGB"
@pirey
pirey / sample.nix
Created June 5, 2023 17:39
create service in nixos configuration
# https://www.reddit.com/r/NixOS/comments/mwbr8t/comment/gvhm2mh/?utm_source=share&utm_medium=web2x&context=3
systemd.services.touchegg = {
enable = true;
description = "Touchégg. The daemon.";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
Group = "input";
Restart = "on-failure";
RestartSec = 5;
@pirey
pirey / profile
Created May 16, 2023 07:33
powershell goodies
# nvim $profile - to edit the file
Import-Module PSFZF # enable fzf keybinding
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete # enable autocomplete