Skip to content

Instantly share code, notes, and snippets.

@ntns
ntns / safeshellscripts.txt
Created April 6, 2022 10:27
Writing Safe Shell Scripts
# Copied from https://sipb.mit.edu/doc/safe-shell/
Writing shell scripts leaves a lot of room to make mistakes, in ways that will cause your scripts to break on certain input, or (if some input is untrusted) open up security vulnerabilities. Here are some tips on how to make your shell scripts safer.
Don't
The simplest step is to avoid using shell at all. Many higher-level languages are both easier to write the code in in the first place, and avoid some of the issues that shell has. For example, Python will automatically error out if you try to read from an uninitialized variable (though not if you try to write to one), or if some function call you make produces an error.
One of shell's chief advantages is that it's easy to call out to the huge variety of command-line utilities available. Much of that functionality will be available through libraries in Python or other languages. For the handful of things that aren't, you can still call external programs. In Python, the subprocess module is very useful for
@ntns
ntns / utils.ts
Created April 5, 2022 17:43
tagged template strings - join maps like jsx does
export function j(strings: TemplateStringsArray, ...values: any) {
return strings
.map((string: string, i: number) => {
return Array.isArray(values[i])
? string + values[i].join("")
: string + (values[i] || "");
})
.join("");
}
@ntns
ntns / names.txt
Created June 29, 2012 15:17 — forked from mahemoff/names.txt
Reserved username list
###
A meta-compilation of:
https://raw.github.com/gist/1453705/d253733a56632a8d2c29321a75c18b627fa4dda8/reserved_usernames.rb
http://blog.postbit.com/reserved-username-list.html
http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
(Took out some company-specific terms at the top of the first one (e.g. imulus, stacks), added one term so far - 'edits'.)
NOTE: Does not include profanities. You may or may not want to add a list of those.
(See https://www.google.com/search?q=profanity+list, but don't try to apply regexp's here because Scunthorpe - http://en.wikipedia.org/wiki/Scunthorpe_problem)