Just simple methods to keep the code clean.
Inspired by progrium/bashstyle and Kfir Lavi post.
- All code goes in a function
- Always double quote variables
# Adapted from https://github.com/bennofs/nix-index/blob/master/command-not-found.sh | |
command_not_found_handle () { | |
if [ -n "${MC_SID-}" ] || ! [ -t 1 ]; then | |
>&2 echo "$1: command not found" | |
return 127 | |
fi | |
echo -n "searching nix-index..." | |
ATTRS=$(@nix-locate@ --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$1") |
Just simple methods to keep the code clean.
Inspired by progrium/bashstyle and Kfir Lavi post.
interface Circle { | |
type: 'circle'; | |
radius: number; | |
} | |
interface Square { | |
type: 'square'; | |
width: number; | |
} |
import { env, MissingEnvironmentVariableError, InvalidEnvironmentVariableError } from 'src/Application/env'; | |
describe('Environment Variable Loader', () => { | |
const originalProcessEnv = Object.assign({}, process.env); | |
afterEach(() => { | |
process.env = originalProcessEnv; | |
}); | |
describe('Default values with non-existent env vars', () => { |
import { expect } from 'chai'; | |
import * as Str from 'src/Support/String'; | |
const app: any = {}; | |
const otherMumboJumbo: any = {}; | |
const validStatusCode = 200; | |
const invalidStatusCode = 500; | |
describe('String utility', () => { | |
describe('slugify', () => { |
// TODO: We need an overload for a default value so it doesn't throw | |
function env(name: string): string; | |
function env<T>(name: string, transformer: (dirty: string) => T): T; | |
function env<T>(name: string, transformer?: (dirty: string) => T): T | string { | |
const value = process.env[name]; | |
if (value == undefined) { | |
// todo: should null be allowed? it might be a valid value for some | |
// consumers instead of defaulting to an empty string. | |
throw new Error(`Missing environment variable: ${name}`); |
import * as express from 'express'; | |
declare module 'express' { | |
interface Request { | |
body: unknown; | |
cookies: Record<string, unknown>; | |
params: Record<string, unknown>; | |
query: Record<string, unknown>; | |
route: Record<string, unknown>; | |
signedCookies: Record<string, unknown>; |
interface Person { | |
name: string; | |
spent: number; | |
} | |
class Trip { | |
private people: Person[]; | |
constructor() { | |
this.people = []; |
#!/bin/sh | |
# | |
# chkconfig: 2345 55 25 | |
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx | |
# For Debian, run: update-rc.d -f nginx defaults | |
# For CentOS, run: chkconfig --add nginx | |
# | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all |