Skip to content

Instantly share code, notes, and snippets.

View Manc's full-sized avatar

Nick Singleton Manc

  • Kraken Technologies
  • Manchester, UK
View GitHub Profile

Keybase proof

I hereby claim:

  • I am manc on github.
  • I am nicksg (https://keybase.io/nicksg) on keybase.
  • I have a public key ASC4ucCFuzV10dRfWB4sQ02pGC4vl9OuSbve8tIfaOb9AAo

To claim this, I am signing this object:

@Manc
Manc / array-filter.ts
Created June 22, 2022 06:41
Useful TypeScript code snippets
/**
* Filter array of mixed type elements narrowing down the resulting types,
* e.g. from `string | null` to just `string`.
*/
const mixedArray: Array<string|null> = ['a', 'b', null, ''];
const strings: string[] = mixedArray
.filter(
(value): value is string => typeof value === 'string'
);
@Manc
Manc / dynamodb-transfer.js
Created May 2, 2018 10:39
Simple Node.js script to transfer data from one AWS DynamoDB table to another table or account
const { spawnSync } = require('child_process');
const options = {
awsCliBinary: '/usr/local/bin/aws',
awsProfileSource: 'profile1',
awsRegionSource: 'eu-west-1',
awsTableSource: 'table1',
awsProfileTarget: 'profile2',
awsRegionTarget: 'eu-west-2',
awsTableTarget: 'table2',
@Manc
Manc / .bash_profile
Last active September 21, 2016 13:47
Cloud Under terminal theme for the macOS Terminal.app and a Bash profile with Linux colours + Node bin aliases
export CLICOLOR=1
export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
# Gulp and Bower CLI without installing them globally
alias gulp="./node_modules/.bin/gulp"
alias bower="./node_modules/.bin/bower"
@Manc
Manc / consul.service
Last active July 15, 2020 03:03 — forked from yunano/consul.service
/etc/systemd/system/consul.service
[Unit]
Description=Consul service discovery agent
Requires=network-online.target
After=network.target
[Service]
User=consul
Group=consul
PIDFile=/run/consul/consul.pid
Restart=on-failure
@Manc
Manc / mongodb.repo
Created January 8, 2016 18:24
MongoDB version 3.2 repository for CentOS 7 (and RedHat...); /etc/yum.repos.d/mongodb.repo
[MongoDB]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1
@Manc
Manc / generate-rsa.sh
Created January 6, 2016 20:56
Generate new private key and Certificate Signing Request (CSR) for SSL certificates
#!/bin/bash
# ------------------------------------------------------------------------------
# This script will generate a new private key and a Certificate Signing Request
# (CSR) using OpenSSL.
# This script is non-interactive. Instead it uses the variables set at the
# beginning of this script. Alternatively you can adapt this script easily
# to read the values differently as required.
# Developed and tested on Mac OS only, but should work on Linux too.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
#
@Manc
Manc / parse-query-string.js
Last active August 29, 2015 13:57
Parse Query String in JavaScript. Demo: http://jsfiddle.net/nicz/hyDKE/
/**
* Convert a URL or just the query part of a URL to an
* object with all keys and values.
* Usage examples:
* // Get "GET" parameters from current request as object:
* var parameters = parseQueryString(window.location.search);
*/
function parseQueryString(query) {
var obj = {},
qPos = query.indexOf("?"),
@Manc
Manc / jquery-nolinebreaks.js
Last active August 29, 2015 13:56
jQuery extension to prevent line breaks in textareas. Demo: http://jsfiddle.net/nicz/Z77YQ/1/
/**
* Disallow line breaks in textareas. Line breaks are converted to
* a space character or any other replacement.
* Usage examples:
* // Convert line breaks only once to spaces (default):
* $('textarea').nolinebreaks();
*
* // Convert line breaks only once to something else:
* $('textarea').nolinebreaks(' / ');
*