Skip to content

Instantly share code, notes, and snippets.

View uudashr's full-sized avatar

Nuruddin Ashr uudashr

View GitHub Profile
@uudashr
uudashr / go-coverage-chehck.sh
Last active June 17, 2020 04:59
Golang coverage check, limit to min threshold
#!/bin/sh
# Ref:
# - https://pretzelhands.com/posts/command-line-flags
# Usage:
# go test -race -v -coverprofile=coverage.out
# ./cover-check.sh coverage.out 70
@uudashr
uudashr / Dockefile
Last active July 15, 2022 00:52
Docker and entrypoint
# == Builder ==
FROM golang:1.13.7-alpine3.11 as builder
RUN apk add --no-cache \
bash=5.0.11-r1 \
git=2.24.1-r0 \
mercurial=5.2.1-r0 \
openssh-client=8.1_p1-r0
ARG SSH_PRIVATE_KEY
@uudashr
uudashr / zsh-docker.sh
Last active December 21, 2018 13:12
ZSH Docker Completion
# docker completion
curl -fLo ~/.zprezto/modules/completion/external/src/_docker https://raw.githubusercontent.com/docker/cli/master/contrib/completion/zsh/_docker
# docker-compose completion
curl -fLo ~/.zprezto/modules/completion/external/src/_docker-compose https://raw.githubusercontent.com/docker/compose/master/contrib/completion/zsh/_docker-compose
compinit
@uudashr
uudashr / settings.json
Last active May 31, 2018 04:40
VS Code - Go project common settings
{
"go.autocompleteUnimportedPackages": true,
"go.gocodeAutoBuild": true,
"go.buildOnSave": "off",
"go.testOnSave": true,
"go.testFlags": ["-short"],
"go.lintTool": "golangci-lint",
"go.lintFlags": [
@uudashr
uudashr / lint-go.sh
Last active May 31, 2018 04:41
Golang linter scripts for golangci-lint
#!bin/sh
golangci-lint run \
--exclude-use-default=false \
--enable=golint \
--enable=gocyclo \
--enable=goconst \
--enable=unconvert \
--exclude='^Error return value of `.*\.Log` is not checked$$' \
--exclude='^G104: Errors unhandled\.$$' \
@uudashr
uudashr / buddyworks-tag.yaml
Created May 16, 2018 07:47
Tag an existing image on buddy works
- pipeline: "Staging "
trigger_mode: "ON_EVERY_PUSH"
ref_name: "master"
ref_type: "BRANCH"
actions:
- action: "Build Docker image"
type: "DOCKERFILE"
login: "$DOCKER_LOGIN"
password: "$DOCKER_PASS"
docker_image_tag: "$BUDDY_EXECUTION_REVISION,stage"
@uudashr
uudashr / delay.js
Created October 13, 2017 04:17
Delaying events
function timeout(millis) {
return new Promise((resolve, reject) => {
setTimeout(resolve, millis);
});
}
class Dispatcher {
constructor() {
this.listeners = [];
this.delayedListeners = [];
@uudashr
uudashr / costly.js
Last active September 12, 2017 08:49
Handle costly promise in NodeJS
// Timeout promise for delaying something
function timeout(millis) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, millis);
})
}
// Costly function, it require 1sec every invocation.
@uudashr
uudashr / json.go
Created March 30, 2017 13:51
Custom JSON time.Time format
const jsonTimeLayout = "2006-01-02T15:04:05+07:00"
// JSONTime is the time.Time with JSON marshal and unmarshal capability
type JSONTime struct {
time.Time
}
// UnmarshalJSON will unmarshal using 2006-01-02T15:04:05+07:00 layout
func (t *JSONTime) UnmarshalJSON(b []byte) error {
parsed, err := time.Parse(jsonTimeLayout, string(b))
@uudashr
uudashr / generate.sh
Created March 24, 2017 06:23
Create big file
#!/bin/bash
for i in {1..10000}; do
echo "[$(date)] - Lorem ipsum dolor sit amet, consectetur adipisicing elit -> $i" >> log/app.log;
done