Skip to content

Instantly share code, notes, and snippets.

View mochow13's full-sized avatar

Mottakin Chowdhury mochow13

View GitHub Profile
package main
import "fmt"
var messages = []string{
"The world itself's",
"just one big hoax.",
"Spamming each other with our",
"running commentary of bullshit,",
"masquerading as insight, our social media",
package main
import (
"fmt"
"sync"
)
var messages = [][]string{
{
"The world itself's",
package main
import (
"fmt"
"sync"
)
const producerCount int = 4
var messages = [][]string{
package main
import "fmt"
var messages = []string{
"The world itself's",
"just one big hoax.",
"Spamming each other with our",
"running commentary of bullshit,",
"masquerading as insight, our social media",
package main
import (
"fmt"
)
var messages = []string{
"The world itself's",
"just one big hoax.",
"Spamming each other with our",
@mochow13
mochow13 / System Design.md
Created May 11, 2019 16:56 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@mochow13
mochow13 / fibs.cpp
Last active September 18, 2018 16:32
std::vector<int> fibs(10,1);
std::adjacent_difference(begin(fibs),end(fibs)-1,begin(fibs)+1,std::plus<>{});
std::vector<int> collection={6,5,3,2,1,4,6,7};
std::vector<int> diffs;
std::adjacent_difference(begin(collection), end(collection), std::back_inserter(diffs));
// The first element of diffs will be same as the first element of collection
std::vector<int> collection={6,5,3,2,1,4,6,7};
std::vector<int> sums, mults;
// contains the partial sum of collection in result
std::partial_sum(begin(collection), end(collection), std::back_inserter(sums));
// contains the partial product
std::partial_sum(begin(collection), end(collection), std::back_inserter(mults), std::multiplies<int>());
// you can also use your own binary operation
std::vector<int> collection={6,5,3,2,1,4,6,7};
// Note that we are providing 0 as the initial value, as it should be
// std::plus<int>() tells that the function should do sums
int sum = std::accumulate(begin(collection), end(collection), 0, std::plus<int>());
// What would happen if initial value was 0 instead of 1 in this call?
int prod = std::accumulate(begin(collection), end(collection), 1, std::multiplies<int>());
// You can also use your custom binary operation
// This also calculates summation. Note that at the beginning accumulate takes
// the initial value (0) to the argument x, the first value in the collection (6)
// to argument y, do the operation, then assigns it to the accumulated value. In the second call,