Skip to content

Instantly share code, notes, and snippets.

View asnimansari's full-sized avatar
🎯
Focusing

Asnim P Ansari asnimansari

🎯
Focusing
View GitHub Profile
git branch | grep -v "master" | xargs git branch -D
@asnimansari
asnimansari / CSVToMap.go
Last active May 13, 2019 07:33
This is a golang function which can convert a reader to an array of dicts with headers and values
// CSVToMap takes a reader and returns an array of dictionaries, using the header row as the keys
func CSVToMap(reader io.Reader) []map[string]string {
r := csv.NewReader(reader)
rows := []map[string]string{}
var header []string
for {
record, err := r.Read()
if err == io.EOF {
break
@asnimansari
asnimansari / hoisting-example.js
Last active June 14, 2019 07:58
Within the function, we first declare the name variable with the var keyword. This means that the variable gets hoisted (memory space is set up during the creation phase) with the default value of undefined, until we actually get to the line where we define the variable. We haven't defined the variable yet on the line where we try to log the nam…
function main() {
console.log(name);
console.log(age);
var name = "Asnim P Ansari";
let age = 23;
}
main();
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
const shape = {
radius: 10,
diameter() {
return this.radius * 2;
},
perimeter: () => 2 * Math.PI * this.radius
};
shape.diameter();
shape.perimeter();
+true;
!"Asnim";
[..."Asnim"];
!!null;
!!"";
!!1;
[[0, 1], [2, 3]].reduce(
(acc, cur) => {
return acc.concat(cur);
},
[1, 2]
);
(() => {
let x, y;
try {
throw new Error();
} catch (x) {
(x = 1), (y = 2);
console.log(x);
}
console.log(x);
console.log(y);