-
Goroutines are lightweight threads
-
Goroutines run in the same address space
-
What’s an address space?
that’s saying that if you have concurrent access to shared memory you must synchronize it. More specifically, if we let A be a variable, you cannot have multiple goroutines reading and writing to A without synchronization
-
-
Channels are the default structures to send and receive values between goroutines
By default, sends and receives block until the other side is ready. This allows goroutines to synchronize without explicit locks or condition variables.
-
The following code waits till c receives two values.
x, y := <- c, <- c- Ask a clarifying question about how does it know when to block or not
Sends to a buffered channel block only when the buffer is full. Receives block when the buffer is empty.
- Ask a clarifying question about how does it know when to block or not
-
time.Sleepis blocking
-
If you want to add stuff to previous commits:
# OLDCOMMIT is the commit hash like abcd123 git add <my fixed files> git commit --fixup=OLDCOMMIT git rebase --interactive --autosquash OLDCOMMIT^
Learnt about windows functions while trying to find out the answer to this question
If the code panics inside a function in Gin, it sends 500 instead of exiting the process! :chef’s kiss:
-
afdfsf
-
sff
-
Using ImageMagick’s
convertto merge two photos.-
To merge vertically:
convert input1.png input2.png -append output-that-is-created.pngIf your photos are of different width, you’ll likely get an ugly padding. As a workaround, you can limit the maximum width to be <= to the width of the photo with the minimum width like:
convert input1.png input2.png input3.png input4.png -geometry x1000 -append output-that-is-created.pngassuming the minimum width among the 4 inputs is <= 1000px.
-
To merge horizontally,
+appendinstead of-append. The logic for padding and width constraint applies to heights here. -
Using
identifyto get basic photo information:identify image1.png
-
-
I stumbled upon this Postmark issue and so I made this gist to help.
Used
pupto parse the webpage along withjq. Here’s the command for doing what I achieved:cat downloaded.html \ | pup 'json{}' \ | jq '[.[].children[] | select(.tag == "strong" and .text != null) | .text] | map(split(" - ")) | map({ code: .[0], message: .[1] })' \ > out.jsonObviously, I won’t remember a lot so here’s a super cool
jq cheat sheet -
The
::markerpseudo-element can be used for stylinglimarkers.
-
MongoDB
$mapoperator is pretty cool. -
I wanted to update a MongoDB collection. A simple operation. Move all the items from one array field to an other array field. It resulted in 2 hours of documentation scouring but I finally got it.
In MongoDB
db.collection.update(), you have to specify the update query (the second paramter) as an array to pass it as a pipeline. Some operations won’t work including references to document fields with$notation.Here’s the forum post I made and solved myself.
-
Bash is pretty easy to learn but I still have to come across its whitespace nuances.
-
Google spent a lot of time and research into finding a SHA-1 collision. Here.
-
RSA works on the principle of how difficult it is to factorise large (like 617 digits large) numbers. More info here
-
Redeemed Educative’s GitHub scholarship
-
Applied to a copule of internships:
- FamPay (found via LinkedIn)
- Tilt (via AngelList)
- Shortlisted a few FinTech startups
-
SendGrid sucks. They put our account under review because we did not use it for a while. There were no pending payments whatsoever. Shifted to Postmark and Mailersend. Going to try them before shifting totally.
This is how you split a string: http://www.cplusplus.com/faq/sequences/strings/split/#string-find_first_of or best way using the std lib:
#include <sstream>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<string> strings;
istringstream f("denmark;sweden;india;us");
string s;
while (getline(f, s, ';')) {
cout << s << endl;
strings.push_back(s);
}
} - MongoDB: You cannot mix inclusion and exclusion, the only exception is the
_idfield. Look here. - JavaScript
- Learnt about
flatMap. Solved an SO question using that:
Going to use it instead of chaining filters and map.const arr = [1, 2, 3, 4, 5]; const str = arr .flatMap((val, i, _arr) => i !== arr.length - 1 ? `${val} => ${_arr[i + 1]}` : [] ) .join(", "); console.log(str); // "1 => 2, 2 => 3, 3 => 4, 4 => 5"
- Learnt about
- Some blogs I discovered
- Daniel Stenberg (Creator of curl)
- Matt Mullenburg
- Martin Tournoij
- Julia Evans
I accidentally cleared a production database…
This is my query:
const deleted = db
.getCollection("oplog.rs")
.find({ op: "d", ns: "e_summit_2021.users" }, { "o._id": 1 })
.sort({ ts: -1 });
db.getCollection("oplog.rs")
.find(
{ op: "i", ns: "e_summit_2021.users", $in: { "o._id": deleted } },
{ o: 1 }
)
.sort({ ts: -1 }); HNY!
Found this cool table:
| , | / | : | ; | = | ? | @ | [ | ] |
|---|---|---|---|---|---|---|---|---|
| %2C | %2F | %3A | %3B | %3D | %3F | %40 | %5B | %5D |
| ! | # | $ | & | ‘ | ( | ) | * | + |
|---|---|---|---|---|---|---|---|---|
| %21 | %23 | %24 | %26 | %27 | %28 | %29 | %2A | %2B |
-
Installed and integrated Cmder and successfully integrated it with Windows Terminal and VS Code. Loving it so far. This is exactly what I was looking for in a terminal on Windows!
-
git pruning:
-
git remote prune originremoves all the remote stale deleted branches. Use cases: Some branches remain in theorigin/***when you do agit branch -a. Pruning sort of cleans up the repository. I’ll be using this mostly.git fetch -pprunes and fetches everything locally.
-
Learnt (again) about Mongoose SchemaTypes. Clarified one thing:
let mySchema = new mongoose.Schema({ name: String, hobbies: [String], friends: [{ name: String, hobbies: [String] }], });is same as
let mySchema = new mongoose.Schema({ name: { type: String }, hobbies: [{ type: String }], friends: [ { name: { type: String }, hobbies: [{ type: String }], }, ], });