-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMisc.txt
More file actions
5349 lines (3988 loc) · 157 KB
/
Misc.txt
File metadata and controls
5349 lines (3988 loc) · 157 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Notes on all other technical stuff I learn.
@@@@@@@@@@@@@@@@@@@@@ PROGRAMMING @@@@@@@@@@@@@@@@@@@@@@@@@@
Rob Pike's 5 Rules of Programming
Rule 1. You can't tell where a program is going to spend its time. Bottlenecks
occur in surprising places, so don't try to second guess and put in a
speed hack until you've proven that's where the bottleneck is.
Rule 2. Measure. Don't tune for speed until you've measured, and even then
don't unless one part of the code overwhelms the rest.
Rule 3. Fancy algorithms are slow when n is small, and n is usually small.
Fancy algorithms have big constants. Until you know that n is
frequently going to be big, don't get fancy. (Even if n does get big,
use Rule 2 first.)
Rule 4. Fancy algorithms are buggier than simple ones, and they're much harder
to implement. Use simple algorithms as well as simple data structures.
Rule 5. Data dominates. If you've chosen the right data structures and
organized things well, the algorithms will almost always be
self-evident. Data structures, not algorithms, are central to
programming.
Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Premature optimization
is the root of all evil."
Ken Thompson rephrased Pike's rules 3 and 4 as "When in doubt, use brute
force.".
Rules 3 and 4 are instances of the design philosophy KISS.
Rule 5 was previously stated by Fred Brooks in The Mythical Man-Month. Rule 5 is
often shortened to "write stupid code that uses smart objects".
Reference:
http://users.ece.utexas.edu/~adnan/pike.html
@@@@@@@@@@ RIPGREP @@@@@@@@
rg –help | more Make help useful on Windows
rg -l NEEDLE List matching files only
rg -c NEEDLE List matching files, including a count
rg -i NEEDLE Search case-insensitively
rg --no-filename NEEDLE Don’t print filenames, handy when you care about the match more than the file
rg -v NEEDLE Invert matching: show lines that do not match
rg NEEDLE README.md Search only in specified file(s)
rg -c ‐‐sort path|modified|accessed|created NEEDLE Sort the results (-sortr to reverse)
rg -g '*.nuspec' NEEDLE Only search in *.nuspec files (can use multiple -g)
rg -g '!*.nuspec' NEEDLE Search in everything but *.nuspec files
rg -g 'folder/*' NEEDLE Search in `folder`
rg -g '!folder/*' NEEDLE Search everywhere except in `folder`
rg -p NEEDLE | less -R Force pretty printed output even in pipes
rg -e NEEDLE1 -e NEEDLE2 Search for multiple patterns
rg -z NEEDLE Search in gzip, bzip2, xz, LZ4, LZMA, Brotli and Zstd compressed files
rg --type-list Displays built-in available types and their corresponding globs
rg -tcs -tconfig Search in file types cs and config
rg -Tconfig Don’t search in file type config
rg image utils.py Search in a single file utils.py
rg image src/ Search in dir src/ recursively
rg image Search image in current dir recursively
rg '^We' test.txt Regex searching support (lines starting with We)
rg -i image Search image and ignore case (case-insensitive search)
rg -s image Smart case search
rg -F '(test)' Search literally, i.e., without using regular expression
rg image -g '*.py' File globing (search in certain files), can be used multiple times
rg image -g '!*.py' Negative file globing (do not search in certain files)
rg image --type py or rg image -tpy Search image in Python file
rg image -Tpy Do not search image in Python file type
rg -l image Only show files containing image (Do not show the lines)
rg --files-without-match image
Show files not containing image
rg -v image Inverse search (search files not containing image)
rg -w image Search complete word
rg --count Show the number of matching lines in a file
rg --count-matches Show the number of matchings in a file
rg neovim --stats Show the searching stat (how many matches, how many files searched etc.)
Reference:
[1] https://www.philipdaniels.com/blog/2019/ripgrep-cheatsheet/
[2] https://jdhao.github.io/2020/02/16/ripgrep_cheat_sheet/
@@@@@@@@@@ CFFI @@@@@@@@@@@
- C Foreign Function Interface.
https://av.tib.eu/media/21110
@@@@@@@@@@ Homebrew Commands @@@@@@@@@@
# Install nightly
brew install --HEAD <package>
@@@@@@@@@@ XML @@@@@@@@@@@
Various Nodes and their meaning
---
<union> - Collection of other nodes such as sequences, elements etc. Handlers
cannot be on this node.
<sequence> - 0 or more collection of nodes, such as element nodes. Handlers are
on this node.
<element> - Can be optional. Must provide a value after this. This is leaf node
in XML.
<choice>
<validator>
<attr-req>
@@@@@@@@@@ VLC Media Player Shortcut Keys @@@@@@@@@@@
Jumps:
Very short backwards jump (3s): Shift + Left (Ctrl + Cmd + Left)
Very short forward jump (3s): Shift + Right (Ctrl + Cmd + Right)
Short backwards jump (10s): Alt + Left (or just Left)
Short forward jump (10s): Alt + Right (or just Right)
Medium backwards jump (1m): Ctrl + Left (Shift + Cmd + Left)
Medium forward jump (1m): Ctrl + Right (Shift + Cmd + Right)
Speed:
[+]/-/= Faster, slower, normal
[ or – : Decrease playback speed. [ decreases it by less, and – decreases it by
more.
] : Increase playback speed
= : Return to the default playback speed
@@@@@@@@@@@@@@@@@@@ QEMU NOTES @@@@@@@@@@@@@@@@@@
// Basic qemu tutorial
https://fosspost.org/tutorials/use-qemu-test-operating-systems-distributions
// On Windows, download Intel's Hardware Acceleration (HAX) technology
www.qemu.org/2017/11/22/haxm-usage-windows/
// pre-built qcow2 images
https://people.debian.org/~aurel32/qemu/amd64/
// To start an image
qemu-system-x86_64 -drive format=raw,file=debian-8.2.0-amd64-DVD-1.iso
For me, following steps worked:
1. Download qemu
2. Download HAX
3. Run above command
@@@@@@@@@@@@@@@@@@@ NODEJS NOTES @@@@@@@@@@@@@@@@@@
Reading/Learning NodeJS
=====
- Use of 'var' and 'const'
- global object, modules
- Module wrapper function:
* All code is wrapped inside this wrapper
(function (exports, require, module, __filename__, __dirname__) {
/* your code */
})
- Template strings (Javascript concept - ES6)
Events and Signals
==================
- Look at this code:
const EE = require('events'); // events class.
const em = new EE();
* here EE is a CLASS and not an object of a class, a method or a variable
* therefore, em is an instance of EE() class
em.emit("signalEvent", {id: 1, url: 'http://'});
- A listener must listen to above event
em.on('signalEvent', function(eventArg) {
console.log('signalEvent invoked. Listener called', eventArg);
})
- Arrow functions
em.on('signalEvent', (eventArg) => {
console.log('signalEvent invoked. Listener called', eventArg);
})
Reference:
[1] https://www.youtube.com/watch?v=TlB_eWDSMt4
@@@@@@@@@@@@@@@@@@@@ GCP SDK Commands Cheat Sheet @@@@@@@@@@@@@@@@@@@@@@@@
Deploy your app
$ gcloud app deploy
List gcloud configurations
$ gcloud list
You can stream logs from the command line by running
$ gcloud app logs tail -s default
To view your application in the web browser run
$ gcloud app browse
gcloud functions deploy helloGCSGeneric --runtime nodejs6 --trigger-resource gcs-cf-nodejs --trigger-event google.storage.object.finalize
[1] https://gist.github.com/pydevops/cffbd3c694d599c6ca18342d3625af97
[2] https://github.com/gregsramblings/google-cloud-4-words
@@@@@@@@@@@@@@ GCP Functions Emulator Commands Cheat Sheet @@@@@@@@@@@@@@@@@
// prefix below commands with `gcloud` and you can do everything with gcloud SDK
// instead of function emulators
$ functions --help
$ functions <command> --help
$ functions config set projectId PROJECT_ID
$ functions start
$ functions deploy helloGET --trigger-http
$ functions call helloGET
$ functions call helloGreeting --data '{"name":"Local Emulator"}'
$ functions debug <function-name>
$ functions inspect <function-name>
$ functions delete FUNCTION_NAME
$ functions reset FUNCTION_NAME
$ functions list
$ functions logs read
$ functions logs clear
$ functions status << status of log file
$ functions stop
$ functions kill
@@@@@@@@@@@@@@@@@@@ RabbitMQ vs Apache Kafka @@@@@@@@@@@@@@@@@@
Origins:
========
RMQ is a message broker and first mature open source implementation of AMQP.
It's written in Erlang. AMQP is an "Open Wire Protocol" for messaging with
powerful routing features. While language specific message brokers existed, AMQP
was first cross-language protocol and RMQ its most mature implementation.
Kafka came from LinkedIn, written in Scala and solved the problem to connect
different internal systems. Adopted by Apache SF and useful in event-driven
architecture.
Architecture & Design
=====================
RMQ is a general purpose message broker. A broker in RMQ comprises of two
components: Exchange and Queues
- Exchange takes messages from Producer and maps it to Queues
- Consumer reads messages from Queues
This way, Producer and Consumer are decoupled. Messaging can be synchronous or
asynchronous as required. RMQ uses smart broker/dumb consumer model.
+---------+
+---->| Queue |---------> Consumer
| +---------+
|
|C
+-----------+ |
A | | | +----------+
Producer -------> Exchange |-------->| Queue |--------> Consumer
| B | | +----------+
+-----------+ |
|
| +----------+
+---->| Queue |--------> Consumer
+----------+
A = Message + Routing Key
B = Exchange Types (4 types)
C = Binding + Binding Key. Binding is mapping Exchange with Queue
There are 4 types of exchanges: Direct, Topic, Fanout, Headers
There's also a default (nameless) exchange where routing key is compared with
queue name
Exchange uses "routing keys" to "bind" queues to message. A routing key is
generated for a message and used to determine which queue(s) it must be
forwarded to
Direct Exchange: 1:1 mapping between message and queue.
Routing Key == Binding Key
Fanout: Every message is routed to ALL queues
Topic: Routing Key is partially matched to Binding Key. Not clear how it's done.
Header: There's no routing key. Message header is used in Queue matching
Messages are removed from the queue after Consumer reads it.
RMQ can be setup on multi-node cluster and make it distributed deployment (HA
etc).
Apache Kafka is not a message broker but more like a message "store" or message
"log". It is fundamentally different in implementation (distributed). Kafka uses
Zookeeper to implement and manage all distributed concepts (leader election,
config management, replication state management etc)
Kafka uses dumb broker/smart consumer model in the sense that consumer is
responsible for maintaining message offsets.
Topics and Partitions:
---
Kafka uses topics and partitions within the topics that acts similar to RMQ
queue. A topic can have many partitions. Ordering of messages within a partition
is FIFO.
Consumer Groups:
---
Kafka has concept of Consumer Groups, where a bunch of Consumer nodes are
grouped together (duh!). This is used to expand and reduce based on message flow
in partitions. There is 1:1 mapping of partition and consumer node. There cannot
be two consumer nodes from same consumer group reading from same partition.
Offset maintenance will be a problem. Offsets per partition are maintained per
consumer group.
Requirements and Use Cases
==========================
TBD
Security
========
TBD
Developer Experience
====================
TBD
Performance
===========
TBD
Making the Call
===============
TBD
Reference:
[1]
https://content.pivotal.io/blog/understanding-when-to-use-rabbitmq-or-apache-kafka
[2] https://www.opsclarity.com/understanding-kafka-consumer-lag/
@@@@@@@@@@@@@@@@@@@ SOAP vs REST @@@@@@@@@@@@@@@@@@
SOAP = Simple Object Access Protocol
REST = Representational State Transfer
- Both are communication protocol for web services
- REST is a stateless protocol and operates through interfaces called resources
(or APIs).
- SOAP exposes application logic as services rather than data.
Benefits of REST over SOAP:
- REST uses HTTP to communicate with APIs. Much simpler protocol than SOAP's
messaging protocols
- REST allows variety of data formats (JSON, YAML). SOAP only uses XML
- REST offers better support for browser clients and has superior performance
- Uses less bandwidth
Benefits of SOAP over REST
-
Reference:
[1] https://stackify.com/soap-vs-rest/
@@@@@@@@@@@@@@@@@@@ ELASTIC SEARCH NOTES @@@@@@@@@@@@@@@@@@
- ES is a document datastore. Documents are stored in JSON format.
- ES uses indices to track documents. We say "Document is added to index XXX"
- Documents also have a type.
Example: Adding a document to ES
----
ADD DOCUMENT TO ES:
POST localhost:9200/accounts/person/1
{
"name" : "John",
"lastname" : "Doe",
"job_description" : "Systems administrator and Linux specialit"
}
index = 'accounts'
document type = 'person'
id = 1
Content of the document is the JSON
Return to above HTTP POST will confirm document creation, as follows:
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
- Let's get the same document back
READ DOCUMENT FROM ES:
GET localhost:9200/accounts/person/1
Response:
---
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "John",
"lastname": "Doe",
"job_description": "Systems administrator and Linux specialit"
}
}
- Look at "_source" for your document
UPDATE THE DOCUMENT:
POST localhost:9200/accounts/person/1/_update
{
"doc":{
"job_description" : "Systems administrator and Linux specialist"
}
}
- Notice that 'specialit' was incorrectly spelled. That is updated now.
SEARCH DOCUMENTS:
GET localhost:9200/_search?q=john
References:
[1] https://www.elastic.co/blog/a-practical-introduction-to-elasticsearch
@@@@@@@@@@@@@@@@@@@ UTF-8 INTRODUCTION @@@@@@@@@@@@@@@@@@@@@@
- Variable sized encoding. Size range from 1 to 4 bytes
How are characters encoded in UTF-8?
- Manipulating numbers at binary level
- High order bits of first byte are important. They tell how many bytes are
used to encode a value
- In 1 byte encoding, which range from 0 to 127, high order bit will always be
zero
+---------------------------+
| 0 | |
+---------------------------+
- In 2 byte encoding, first 3 high order bits of first byte is 110 and first 2
high order bits of second byte is 10
+---------------------------+
| 1 | 1 | 0 | |
+---------------------------+
+---------------------------+
| 1 | 0 | |
+---------------------------+
- This gives 11 (5+6) bits to encode the char
- In 3 byte encoding, we have 1110, 10 and 10 in higher order of each byte
+---------------------------+
| 1 | 1 | 1 | 0 | |
+---------------------------+
+---------------------------+
| 1 | 0 | |
+---------------------------+
+---------------------------+
| 1 | 0 | |
+---------------------------+
- This gives 16 bits (4+6+6) to work with
- 4 byte encoding follows same pattern as 3 byte encoding
+---------------------------+
| 1 | 1 | 1 | 0 | |
+---------------------------+
+---------------------------+
| 1 | 0 | |
+---------------------------+
+---------------------------+
| 1 | 0 | |
+---------------------------+
+---------------------------+
| 1 | 0 | |
+---------------------------+
- Total of 21 chars to work with
Reference
https://www.youtube.com/watch?v=sqPTR_v4qFA
@@@@@@@@@@@@@@@ CPU CACHES @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- Three common types of caches
* Data Cache (D-cache, aka D$)
* Instruction (I-cache, aka I$)
* Translation Lookaside Buffer (TLB)
- Caches virtual addr to real addr
- Cache Hierarchies (per core)
* L1 I-cache, L1 D-cache
* L2 cache
- Holds both instructions and data
* L3 cache
- Holds both instructions and data
- Assume 100MB program at runtime (code+data)
* 8% fits in L3 cache of Intel Core i79xx
* 0.25% fits in each L2 cache
* 0.03% fits in each L1 cache
- Cache speeds (for Core i79xx)
* L1 latency is 4 cpu cycles
* L2 latency is 11 cpu cycles
* L3 latency is 39 cpu cycles
* Main Memory (RAM) is 107 cpu cycles
Cache Lines
---
- Caches consists of "lines", each holding multiple adjacent words
- On Core i7, cache lines hold 64 bytes (common for Intel/AMD processors)
64 bytes = 16 32-bit values, 8 64-bit values, etc
Eg., 16 32-bit array elements
- Main memory read/written in terms of cache lines
* Reading a byte that's not in cache (cache miss) will read a full cache
line from main memory
* Writing a byte will write a full cache line to main memory (eventually)
Reference:
https://www.youtube.com/watch?v=WDIkqP4JbkE
@@@@@@@@@@@@ YAML SYNTAX RULES @@@@@@@@@@@@@@@@@@@@@@@@
RULE 0: Indentation
- YAML uses fixed indentation scheme to represent relationship between data
layers
RULE 1: Scalars
- Scalars are ordinary values: numbers, strings, booleans
Ex:
number-value: 42
floating-point-value: 3.141592
boolean-value: true
# strings can be both 'single-quoted` and "double-quoted"
string-value: 'Bonjour'
RULE 2: Colons (or Dictionaries)
- YAML uses dictionaries represented as key:value pairs, similar to Python
dictionaries
Ex:
[1]
my_key: my_value
[2] Uncommon, but this is valid
my_key:
my_value
- Dictionaries can be nested
Ex:
first_level_dict_key:
second_level_dict_key: value_in_second_level_dict
- There's a space following colon and then value (this is mandatory)
RULE 3: Dashes (or Lists)
- To represent list of items, single dash followed by a space is used.
- Multiple items belong to same list if indentation level is same.
Ex:
- list_value_one
- list_value_two
- list_value_three
- Value of a dictionary can be list
Ex:
my_dictionary:
- list_value_one
- list_value_two
- list_value_three
YAML Mutli Documents
---
- YAML allows multiple docs to be embedded in a single file. They only have to
be separated using triple-dash separator (---)
Reference:
https://learnxinyminutes.com/docs/yaml/ <<<< This is very good, quick intro
https://docs.saltstack.com/en/latest/topics/yaml/
https://gettaurus.org/docs/YAMLTutorial/
@@@@@@@@@@@@@@@@@@@@@@@@@ TOR @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Tor:
- Passing traffic by bouncing them across various Tor nodes across the globe.
Minimum, Tor traffic passes through 3 nodes: Entry/Gaurd, Relay & Exit.
- Traffic is encrypted in layers (like Onion) before it is sent out from source.
# of layers of encryption = # of Tor nodes traffic is passing.
- As traffic passes through each node, that node knows how to decrypt it's layer
and forward to next Tor node.
@@@@@@@@ MUNICIPAL SOLID WASTE MANAGEMENT IN DEVELOPING COUNTRIES @@@@@@@@
Facts:
- Humans generate 7-10 billion tons of waste per year worldwide.
- Waste from 2 billion people is not collected from their homes and
neighborhoods.
- By end of century, 83% of world population will be in Asia and Africa.
- There are 3 billion people who lack access to controlled disposal facilities.
- By 2030 there will be 40 megacities (cities with 10 million or more
population). Of that 32 will be in Asia and Africa.
Municipal Waste Generation and Characterization:
- Estimating Lower Calorific Value (LCV)
LCV = 40(a+b+c+d) + 90e - 46W
LCV in kcal/kg
a = Paper
b = Textiles
c = Wood and leaves
d = Food waste
e = Plastic and rubber
W = Water
all of above in % of wet weight.
- Incineration without adding fuel requies LCV > 1000 kcal/kg
- Incineration with energy recovery requires LCV > 1500-1650 kcal/kg
[1]
https://www.coursera.org/learn/solid-waste-management/home/welcome
@@@@@@@@@@@@@ Open/R @@@@@@@@@@@@@@
- Build a routing _platform_ and not a routing _protocol_
- Applications are built on top of this platform in C++. Routing is one
application.
- Each node in this network as following 4 components:
* Decision
* FIB
* KV-Store
* Link Monitor
- Zero MQ for message passing between nodes.
- Thrift: Message encoding. Populat open source library.
- Key-Value Store:
- Key = Strings, Value = Thrift objects
Optimization in KV Store:
- Group nodes in to clusters
- STP within clusters
- Between clusters, similar to BGP's path tracing mechanism is used.
Scaling in KV Store:
-
Neighbor Discovery:
- Runs as a separate process.
- Works on link-level
[1]
https://code.facebook.com/posts/1036362693099725/networking-scale-may-2016-recap/
[2]
https://code.facebook.com/posts/1142111519143652/introducing-open-r-a-new-modular-routing-platform/
@@@@@@@@@@@@@ Networks Illustrated: Principles w/o Calculus @@@@@@@@@@@@@@
Lesson 1:
---
- 8 principles in this course:
- Sharing (network medium) is hard
- Consensus is hard
* Referral system.
* Auction system with systems bidding.
* Voting system.
- Crowds are wise
* Amazon trying to solve Rating problem.
* Netflix trying to solve Recommendation problem.
- Crowds are NOT wise:
* Information cascade can happen and crowds may not think for themselves.
- Network is Expensive:
- Network of Networks:
* internet is combination of many networks within networks.
- Layers on Layers:
- Bigger & Bigger:
Lesson 2:
---
- Mobile penetration rate:
# of mobile subscriptions/total population
- Multiple Access
* Morse devised Morse Code to use Telegraph Cable to transmit ./- notation.
* Bell devised multiple transmitters and recievers on same Telegraph Cable.
- Frequency Division Multiple Access (FDMA)
* N MHz = N cycles per second.
- 0G
MTS (1946) - Mobile Telephone System
* FDMA system
* An operator was required
IMTS (1964) - Improved MTS
* No operator required
DynaTAC (1973)
* From Qualcomm
- Attenuation
WiFi is in unlicensed frequency
Cellular is in licensed frequency
Attenuation is decaying of signal over distance
- Cell & 1G
+ Due to attenuation, we divided regions in to cells of hexagon shape.
+ Cell towers are at the center of hexagons and base stations at
intersection of edges of hexagons. With this design, a base station can
serve 3 cells.
+ Frequency ranges in one cell doesn't match with next cell to avoid
interference, but they can match with non-adjacent cells. This is done for
spectral efficiency.
- Frequency Reuse Factor
+ Number of frequency bands used.
- 1G
+ Cells were used first time in 1G.
+ AMPS (1986) - Advanced Mobile Phone System. Operated in 800 MHz band
system.
+ Cellular technology transformed from 0G to 1G.
+ First operated in Chicago with 90 people and 10 cells. Demonstrated
feasibility.
- 2G
+ Migration from Analog to Digital is the most significant change from 1G to
2G
+ Digital screens started appearing.
+ Texting was a feature.
+ 2000 was the year when 2G came.
- TDMA (Time Division)
+ TDMA uses Frequency Division with Time Division.
+ Why didn't we do this before? Analog signalling didn't allow this.
+ Sometimes called F/TDMA.
- GSM (Global System for Mobile Communication) 1982
+ First system to employ TDMA
+ 3x more than Analog capacity.
+ GSM was quickly adopted by Europe.
- CDMA (Code Division Multiple Access) 1988
+ CTIA (Cellular Technology Industries Assoc) wanted 10x improvement.
+ Qualcomm had a different idea. They added a different dimension to time
and frequency. A code is added with each communication.
- Codes?
+ Along with digital data signal, a "spreading code" is used to transmit
data. data signal x spreading code is transmitted.
+ Receiver uses spreading code to decode data signal.
+ Designing spreading code is very tough.
+ It needs to have a property called "Orthogonal" that two spreading codes
should cancel out.
- Qualcomm's CDMA improvements
+ Supposedly 40x improvement (theoretically). But in reality, much less.
+ CTIA voted Qualcomm's CDMA as a 2G standard in US.
- Near-Far Problem
+ Channel quality depends on distance from base station and obstacles in
between.
+ How much power is needed to transmit data? It's measure in Watts (W). In
fact, phones need power in milli Watts (mW) to transmit data.
+ Phones that are farther from BS transmit data at, say, 20 mW and by the
time it reaches BS, it's say 2 mW. While those near to BS may be received
at 10 mW. It is important to make these signals reach BS at constant
power. There's easy algo for this.
+ BS tells phones at what power to transmit so it receives at constant
power.
+ Transmit Power Control (TCP) Algorithm to solve NF Problem.
- Signal Quality
+ Power is not the problem. Quality is.
+ Increasing power by a phone causes interference.
+ Signal to Interference Ratio (SIR).
- DPC (Distributed Power Control)
+ Cells transmit data to BS. BS sends SIR to phones. Phones adjust power.
+ This process iterates and finally converges on a power.
[1] https://www.coursera.org/learn/networks-illustrated/home
@@@@@@@@@@@@@@@@@@@@@@@ C++ for C Programmers @@@@@@@@@@@@@@@@@@@@@@@@
- static_cast <new_type> (expression), dynamic_cast <new_type> (expression)
const_cast <new_type> (exp), reinterpret_cast <new_type> (exp)
C++ is better than C (really?)
---
+ More type safe
+ More libraries
+ Less reliance on preprocessor
+ OO vs imperative
C++ Templates
---
template <class T>
inline void swap (T& d, T& s)
{ T temp = s;
s = d;
d = temp;
}
C++ Generics: Sum an array
---
template <class T> //T is a generic type
T sum (const T data[], int size, T s=0)
{
for (int i=0; i<size; i++)
s += data[i]; // += must work for T
return s;
}
- Defaults for function parameter in C++ must be at the end of the param list.
- When multiple default params exists, in a function call, values are assigned
left to right.
void func(int x=10, int y=20, int z=30);
func(1, 2, 3); // x=1, y=2, z=3
func(1, 2); // x=1, y=2, z=30
func(1); // x=1, y=20, z=30
func(); // x=10, y=20, z=30
Multiple Template Arguments
---
- Be careful, as it can get very dangerous.
template <class T1, class T2>
void copy (const T1 src[], T2 dst[], int size)
{
for (int i=0; i<size; i++) {
dst[i] = static_cast<T2> (src[i]);
}
}
- static_cast<> This is safe casting.
C++ casts
---
- 4 types of casting in C++
+ static_cast <type> // considered safe
+ dynamic_cast <type> // used with classes
+ reinterpret_cast <type> // highly unsafe, similar to C
+ const_cast <type> // cast away const-ness
reinterpret_cast and const_cast are usually discouraged by instructor.
Representation of Graph
---
- Edge list representation
- Connectivity matrix (also distances).
List representation:
---
- Representation of directed graph with n verticies using an array of n lists of
vertices.
- List i contains vertex of j if there is an edge from vertex i to vertex j.
- A weighted graph may be represented with a list of vertex/weight pairs.
- An undirected graph may be represented by having vertex j in the list for
vertex i and vertex i in the list for vertex j.
Matrix Representation:
---
- Well known.
- Both these don't capture weight.
Dijkstra Shortest Path
---
TODO: Watch Prof. Bob Sedgwick's video.
Enum
---
typedef enum color {
RED,
WHITE,
GREEN,
} color;
- enum is of type int.
- Unary operators can be overloaded. Their precedence cannot be overriden.
Operator Overloading
---
- Example of overloading ++ operator
typedef enum days {
SUN,
MON,
TUE,
WED,
THU,
FRI,
SAT
} days;
inline days operator++ (days d)
{
return static_cast <days> ((static_cast<int>(d)+1)%7);
}
- Example of overloading << operator
ostream& operator<< (ostream& out, const days& d)
{
switch (d) {
case SUN: out << "SUN"; break;
case MON: out << "MON"; break;
...
}
return out;