Skip to content

Instantly share code, notes, and snippets.

const getDelayed = function (resolveVal) {
return new Promise((resolve) =>
setTimeout(() => resolve("delayed: " + resolveVal), 2000)
);
};
const func1 = function () {
console.log("Hello func1");
return getDelayed("func1");
};
const getPromise = function (resolveValue) {
return Promise.resolve({ result: resolveValue });
};
const handleUsingThen = function () {
return getPromise("doA").then((res) => res.result);
};
const handleAsync = async function () {
const res = await getPromise("doB");
@vidhill
vidhill / dump_raw_response.go
Last active February 24, 2022 13:29
Go, how to dump `http.Response` body to log output using an `io.Writer`, -for debugging purposes
import (
"io"
"log"
"io"
"net/http"
)
func dumpResponse(r http.Response) {
io.Copy(os.Stdout, r.Body)
log.Println("")
@vidhill
vidhill / go.mod
Last active February 3, 2022 14:46
Go: get the value of the json tag from a `struct` instance
module dummy/foo
go 1.14
require (
)
@vidhill
vidhill / main.go
Created February 24, 2022 13:28
Go, print numbers with thousand separators
package main
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
// create a new printer withe the locale set to english
var print = message.NewPrinter(language.English)
@vidhill
vidhill / teereader.go
Created September 16, 2022 13:55
Make copy of response body reader, and dump json
package main
import (
"io"
"net/http"
"os"
"strings"
)
func dummmy(){
#!/bin/bash
#
# Mostly for JS projects
#
# In the scenario where you end up with multiple same name files,
# e.g. `my-component.tsx` `my-component.spec.ts` `my-component.module.css`
#
# It is much tidier to put all related files inside a folder and use an index file naming convention
# e.g. `my-component/index.tsx` `my-component/index.spec.ts` `my-component/index.module.css`