Skip to content

Instantly share code, notes, and snippets.

View packages.md

cli tools

  • inquirer
  • commander
@dfmartin
dfmartin / async-sleep.ts
Created Sep 27, 2019
typescript async sleep
View async-sleep.ts
const sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
View toCamelCase.js
function snakeToCamel(str){
return str.toLowerCase()
// Replaces any - or _ characters with a space
.replace( /[-_]+/g, ' ')
// Removes any non alphanumeric characters
.replace( /[^\w\s]/g, '')
// Uppercases the first character in each group immediately following a space
// (delimited by spaces)
.replace( / (.)/g, function($1) { return $1.toUpperCase(); })
// Removes spaces
@dfmartin
dfmartin / .gitconfig
Last active Aug 23, 2017
git aliases
View .gitconfig
##
[alias]
co = checkout
cob = checkout -B
fp = fetch --prune
# log commands
lsg = log --all --graph --oneline --decorate
ls = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
View prepare-commit-msg
# Currently in .git/hooks. Also check .git_template/
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
View NestedNulls.cs
var x = People[0].Address.City;
// oops! Null reference exception. Need to replace with. . .
string x = string.Empty;
if(People != null) {
var p = People[0];
if (p != null) {
var a = p.Address;
if (a != null) {
x = a.City;
View AutoPropertyInitializersImmutable.cs
public class CurrentSession {
public CurrentSession() {
CreateDate = DateTime.Now;
}
public DateTime CreateDate { get; }
}
View AutoPropertyInitializers.cs
public string FirstName { get; set; } = "John";
public string LastName { get; set; } = "Doe";
View AutoProperties.cs
public string FirstName { get; set; }
public string LastName { get; set; }
@dfmartin
dfmartin / uglyPropertyDefault.cs
Last active Aug 27, 2015
Ugly property defaults
View uglyPropertyDefault.cs
private string _firstName = "John";
private string _lastName = "Doe";
public string FirstName {
get { return _firstName; }
set { _firstName = value; }
}
public string LastName {
get { return _lastName; }