Skip to content

Instantly share code, notes, and snippets.

View melvinlee's full-sized avatar

melvinlee melvinlee

  • Singapore
View GitHub Profile
@melvinlee
melvinlee / Dockerfile
Created August 2, 2018 13:09
Hydrate dotnet nuget packages.
FROM microsoft/dotnet:2.1-sdk
# warmup NuGet package cache
COPY packagescache.csproj /tmp/warmup/
RUN dotnet restore /tmp/warmup/packagescache.csproj \
--source https://api.nuget.org/v3/index.json \
--verbosity quiet \
&& rm -rf /tmp/warmup/
WORKDIR /
@melvinlee
melvinlee / bootstrap.ps1
Last active July 25, 2018 17:16
Windows bootstrap
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install add-on software
choco install docker-for-windows -y
choco install visualstudio2017community -y
choco install dotnetcore-sdk -y
# Enable HyperV for Docker
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
# Restart
Restart-Computer
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y docker.io kubelet kubeadm kubectl
systemctl enable docker
@melvinlee
melvinlee / .gitconfig
Created July 6, 2018 04:00
Git Config
[user]
name = my name
email = [email protected]
[core]
editor = vi
[alias]
aa = add --all
bv = branch -vv
ba = branch -ra
bd = branch -d
@melvinlee
melvinlee / findLongestEvenWord.py
Created April 30, 2018 11:36
Python find longest event word
def findLongestEventWord(sentense):
words = sentense.split()
event_words = [x for x in words if len(x) % 2 == 0]
return sorted(event_words, key=len, reverse=True)[0]
print(findLongestEventWord("The code is self explanatory") == 'code')
print(findLongestEventWord("Once created , you can click on Test and send a JSON as below") == 'Once')
@melvinlee
melvinlee / quickstart-virtualenv.md
Last active April 29, 2018 04:53
Python virtualenv

Create VirtualEnv

$ cd ~/.virtualenvs
$ virtualenv <projectname>
Using base prefix '/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/melvinlee/.virtualenvs/lambda-digitalgift/bin/python3.6
Also creating executable in /Users/melvinlee/.virtualenvs/lambda-digitalgift/bin/python
Installing setuptools, pip, wheel...done.
@melvinlee
melvinlee / lexResponses.js
Created April 19, 2018 13:34
Lex Responses Helper
module.exports.delegate = function(sessionAttributes, slots) {
return {
sessionAttributes,
dialogAction: {
type: 'Delegate',
slots
}
};
};
@melvinlee
melvinlee / ultimate-ut-cheat-sheet.md
Created April 16, 2018 10:47 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies


@melvinlee
melvinlee / gist:d98ee9432cb8fc26ec62dccae5a4250a
Created April 7, 2018 10:58
Execute bash shell from a running docker container
$docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7fe71e1c7bdd redis "docker-entrypoint.s…" 9 seconds ago Up 21 seconds 6379/tcp unruffled_khorana
ad8a33ce3b2b nginx "nginx -g 'daemon of…" 14 minutes ago Up 14 minutes 80/tcp vigorous_meninsky
$docker exec -it 7fe /bin/bash
or
$docker exec -it $(docker ps | awk 'FNR == 2 { print $1; }') /bin/bash
@melvinlee
melvinlee / index.js
Created April 7, 2018 04:29
AWS nodejs lamba to return html content from file.
'use strict';
var fs = require('fs');
exports.get = function(event, context) {
let contents = fs.readFileSync("public/index.html");
context.succeed({
statusCode: 200,
body: contents.toString(),
headers: {'Content-Type': 'text/html'}
});