Skip to content

Instantly share code, notes, and snippets.

ZSH CheatSheet

This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.

Strings

Description Syntax
Get the length of a string ${#VARNAME}
Get a single character ${VARNAME[index]}
#!/usr/bin/zsh
B="/usr/bin/btrfs"
L="/usr/bin/logger"
MOUNT="/mnt/"
SNAPS="/mnt/snaps"
HOTSNAPS="/mnt/hotsnaps"
TODAY=$(/usr/bin/date +\%Y-\%m-\%d)
YESTERDAY=$(/usr/bin/date +\%Y-\%m-\%d --date='yesterday')
HOST=$(hostname)
@artgreen
artgreen / orcamacros.txt
Created September 29, 2024 14:40
ORCA macros
ABSx Integer Absolute Value
ADDx Integer Addition
CMPx Integer Compare
DIVx Integer Division
MODx Integer Modulo Function
MULx Integer Multiplication
RANx Integer Random Number Generator
SIGNx Integer Sign Function
@artgreen
artgreen / jIIgs.asm
Created September 10, 2024 23:16 — forked from sduensin/jIIgs.asm
JoeyLib IIgs ASM Blitter Work
;----------------------------------------
; JoeyLib
; Copyright (C) 2018-2019 Scott Duensing <[email protected]>
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
;
; Unpack a NULL terminated array of6-bit values
; from a packed array of 8-bits
;
*= $800
unpack
ldy #$00 ; first output byte
ldx #$00
unpack1
lda input,x ; get a byte
@artgreen
artgreen / pack63.s
Last active January 26, 2024 02:24
*= $800
;
; pack a null terminated array of bytes with values of $01 - $3f
; result is an array of packed 6-bit values
; useful for compressing text (VAL - $1F) by ~20%
; space = $01, @ = $02, A = $22, etc.
;
; Thanks to: http://retro.hansotten.nl/6502-sbc/kowalski-assembler-simulator/
@artgreen
artgreen / lexer.l
Last active July 31, 2021 21:24
IP address extractor
/*
* Simple IP scanner
* returns 1 if something was found, 0 if nothing was found
*
* $ flex -f lexer.l && gcc -O3 -o cutip lex.yy.c
* <testfile cutip
*/
%{
int found = 0;
%}
#define AbsoluteValue(Num) (Num>=0 ? Num : -Num)
#define GetPrecentage(Numerator, Denominator) (Numerator*100/Denominator)
#define SetBit(value, place) (value | (1 << place))
#define ClearBit(value, place) (value & (~(1 << place)))
#define ToggleBit(value, place) (value ^ (1 << place))
#define GetBit(value, place) ((value >> place) & 1)
#define GetMSB(value, datatype) GetBit(value, (sizeof(datatype) * 4 - 1))
#define GetLSB(value) GetBit(value, 0)
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <pthread.h>