Skip to content

Instantly share code, notes, and snippets.

View uudashr's full-sized avatar

Nuruddin Ashr uudashr

View GitHub Profile
@uudashr
uudashr / 0_reuse_code.js
Created May 18, 2014 11:39
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@uudashr
uudashr / week_bounds.js
Created May 18, 2014 11:55
Get week bounds from a date
/*
* Usage:
* new Date().weekBounds()
*
* or
*
* weekBounds(new Date());
*/
function weekBounds(date) {
@uudashr
uudashr / day_bounds.js
Created May 21, 2014 08:14
Get the bounds of a day
function dayBounds(date) {
var t1 = new Date(date.getTime());
t1.setHours(0, 0, 0, 0);
var t2 = new Date(date.getTime());
t2.setHours(23, 59, 59, 999);
return [t1, t2];
}
@uudashr
uudashr / main.go
Last active October 2, 2023 21:09
Listening for signal termination in Golang (AKA shutdown hook)
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
)
@uudashr
uudashr / ask.sh
Last active March 1, 2017 04:48
Prompt / ask something in shell script
#!/bin/sh
read -p "Install directory [/root]: " installDir; installDir=${installDir:-/root}; echo $installDir
@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
@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 / 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 / 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 / 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"