Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Martin Kealey kurahaupo

🏠
Working from home
  • Sydney, Australia
View GitHub Profile
@kurahaupo
kurahaupo / dialog.bash
Last active Mar 11, 2021
Implementing "dialog" in pure bash
View dialog.bash
#!/bin/bash
# (replace the preceding line with the path to Bash on your system)
# Takes the list of items as command-line parameters
# Interacts using stdin+stderr
# Writes the answer to stdout
# Use like:
# result=$( bash dialog.bash Foo Bar Zot Baz ) || exit
# or
@kurahaupo
kurahaupo / TrueColour.md
Last active Mar 14, 2021 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals
View TrueColour.md

Terminal Colors

There exists common confusion about terminal colors. This is what we have right now:

  • Plain ASCII
  • ANSI escape codes: 16 color codes with bold/italic and background
  • 256 color palette: 216 colors + 16 ANSI + 24 gray (colors are 24-bit)
  • 24-bit true color: "888" colors (aka 16 million)
View poll.bash
status=
dikf() {
z=$( docker inspect "$k" -f "{{.State.$1}}" )
[[ $z = $2 ]]
}
while
read -r k
do
@kurahaupo
kurahaupo / gist:7df6c8a50c04e5b80d84f28938b3e258
Last active Dec 18, 2020
"checked out" vs "checkouted"
View gist:7df6c8a50c04e5b80d84f28938b3e258

Should one say "Checkouted" or "Checked out"?

At the time of writing (2020), most people would agree that the latter is preferred, and that the former is either "wrong" or at best "dubious".

This will eventually change, and perhaps already has by the time you read this.

Indeed I can be fairly confident about that, much as it pains my own sense of what's "right", because there's an inevitability about regularization.

Looking back 50 years to 1970, nobody then would have even thought of saying "checkouted", much less said it out loud, for the simple reason that it was a two-word phrase, a verb and a preposition: "check out".

View sample from dsag.sh
write_key() {
mkdir -p "${JENKINS_AGENT_HOME}/.ssh"
echo "$1" > "${JENKINS_AGENT_HOME}/.ssh/authorized_keys"
chown -Rf jenkins:jenkins "${JENKINS_AGENT_HOME}/.ssh"
chmod 0700 -R "${JENKINS_AGENT_HOME}/.ssh"
}
if [[ $JENKINS_SLAVE_SSH_PUBKEY == ssh-* ]]; then
View gist:ac6b66cfc3c4deda378b0b9798d13c2e
#!/bin/bash
# number of buckets
declare -i nB=6
# values by key
declare -Ai Vk=(
[a]=3632376
[b]=1403349
[c]=1509800
View mod7.sed
/^[0-9]*$/!n
:a
s/^[07]*//
s/^[18]5\|^[29][29]\|^36\|^43\|^5[07]\|^64/1/
s/^[18]6\|^[29][07]\|^3[29]\|^44\|^5[18]\|^65/2/
s/^[18][07]\|^[29][18]\|^33\|^45\|^5[29]\|^66/3/
s/^[18][18]\|^[29][29]\|^34\|^46\|^53\|^6[07]/4/
s/^[18][29]\|^[29]3\|^35\|^4[07]\|^54\|^6[18]/5/
s/^[18]3\|^[29]4\|^36\|^4[18]\|^55\|^6[29]/6/
ta
View gist:f7972e1a7969448c0e99b46c7bc67455
XHow To Write Good
1. Alliterations are awkward; always avoid.
2. Prepositions are not words to end sentences with.
3. A writer needs a cliché like a fish needs a bicycle.
4. Comparisons are as bad as the clichés.
5. Be more-or-less specific.
6. All writers should never generalise.
Seven. Be consistent.
8. Don't be redundant; don't use more words than necessary; avoid being verbose, it's excessively superfluous.
9. Who needs rhetorical questions?
@kurahaupo
kurahaupo / sn_make_path.c
Created Jun 7, 2018
demo of string handling
View sn_make_path.c
/* This functions takes a path to a directory (C:/blah) and a file name (foobar.txt) then returns the full path of the file (C:/blah/foobar.txt) */
size_t sn_make_path(char *buffer, size_t bsize, const char *dir_path, const char *file_name, char dir_sep) {
size_t dir_len = strlen(dir_path);
size_t file_len = strlen(file_name);
int add_slash = dir_len > 0 && dir_path[dir_len - 1] != dir_sep;
size_t file_path_len = dir_len + file_len + add_slash;
if (bsize > 0) {
View gist:508e9901617c990ff2b25940c26d4007
#define BUfSIZ*pick a number
, add #includes, and ADD ERROR HANDLING */
int main(){
char b[N]="/tmp/.spongeXXXXXX";
char*t=mktemp(b);
int f=open(t,O_RDWR|O_CREAT|O_EXCL,0);
unlink(t);
ssize_t n;
while((n=read(0,b,N))>0)