Skip to content

Instantly share code, notes, and snippets.

View rcanepa's full-sized avatar

Renzo Canepa rcanepa

  • Santiago, Chile
View GitHub Profile
@rcanepa
rcanepa / random_string.py
Last active December 1, 2017 15:35
Random String Generator
import string
import random
# The random module also provides the SystemRandom class which uses the system function
# os.urandom() to generate random numbers from sources provided by the operating system.
os_random = random.SystemRandom()
default_characters = string.ascii_letters + string.digits # 62 characters
@rcanepa
rcanepa / sd.md
Last active November 27, 2017 02:07
System Design

System Design

Summary

A strong process is crucial to successfully solving system design questions. We broke it down into four steps:

  • Scope the problem: Don't make assumptions; Ask questions; Understand the constraints and use cases.
  • Sketch up an abstract design that illustrates the basic components of the system and the relationships between them.
  • Think about the bottlenecks these components face when the system scales.
  • Address these bottlenecks by using the fundamentals principles of scalable system design.

The fallacies of distributed systems

@rcanepa
rcanepa / latency.markdown
Created November 23, 2017 13:59 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@rcanepa
rcanepa / gist:ee71e0379b386b49b6e6e0d93676aa5d
Created November 22, 2017 20:45
Transactions across datacenters - Google IO 2009
## Consistency?
### Weak
- After a write, reads may or may not see it
- Best effort only
- Memcached
- VoIP, live online video
- Online multiplayer games
### Eventual
- After a write, reads will eventually see it
@rcanepa
rcanepa / gist:06751b5a25ae6db79da0c8dabe568716
Created September 11, 2017 14:48
How to update Node with NVM
nvm install node --reinstall-packages-from=node
@rcanepa
rcanepa / main.cpp
Created September 5, 2017 00:08
QT DontUseNativeMenuBar Mac
#include "mainwindow.h"
#include <QApplication>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
MainWindow w;
w.show();
@rcanepa
rcanepa / sockets.clj
Created September 3, 2017 15:24
Sockets in Clojure
(def IPaddress "XX.XX.XX.XX")
(def port 1234)
(def socket (Socket. IPaddress port))
(println "Connected:" (.isConnected socket))
(def in (DataInputStream. (BufferedInputStream. (.getInputStream socket))))
(def out (DataOutputStream. (BufferedOutputStream. (.getOutputStream socket))))
(def command "Some string")
(println "Input:" command)
(.writeUTF out command)
@rcanepa
rcanepa / classes.py
Last active August 30, 2017 22:05
Classes, Methods, Class and Instance Variables, Inheritance in Python 3
class Shark:
shark_type = "White Shark" # class variable
def __init__(self, name):
print("I am being constructed!")
self.name = name # instance variable
def swim(self):
print("The shark is swimming.")
@rcanepa
rcanepa / stringFormatters.py
Created August 30, 2017 01:58
String Formatters in Python 3
age = 31.67
"Renzo ist ein {0} {1}, der in {country:*^20} wohnt. Er ist {2:.1f} Jahre alt.".format("sympatischer", "Mensch", age, country="Chile")
=> 'Renzo ist ein sympathischer Mann, der in *******Chile******** wohnt. Er ist 31.7 Jahre alt.'
for i in range(3,13):
print("{:6d} {:6d} {:6d}".format(i, i*i, i*i*i))
=>
3 9 27
@rcanepa
rcanepa / Flex.js
Created August 22, 2017 00:52 — forked from jorilallo/Flex.js
Flexbox component for React
// @flow
import React from 'react';
import styled from 'styled-components';
type GlobalCssValues = 'initial' | 'inherit' | 'unset';
type WrapValue = 'nowrap' | 'wrap' | 'wrap-reverse' | GlobalCssValues;
type JustifyValue =
| 'center'