- Two Pointers:
Use when working with sorted arrays or to solve problems like pair-sum and partitioning (e.g., “left and right pointers meet in the middle”). - Sliding Window:
Ideal for subarray problems—expand or contract the window to meet the required sum or length conditions. - Prefix Sums:
Precompute cumulative sums to answer range queries in O(1) time. - In-place Reversal:
Here’s a quick cheat sheet for common data types and their storage sizes across popular relational databases (like MySQL, PostgreSQL, and SQL Server). Keep in mind that the sizes listed are typical, but some nuances or variations might apply based on specific DBMS configurations.
Data Type | Description | Storage Size (in bytes) |
---|---|---|
TINYINT | Integer between -128 and 127 (signed) | 1 |
SMALLINT | Integer between -32,768 and 32,767 (signed) | 2 |
MEDIUMINT | Integer between -8,388,608 and 8,388,607 | 3 |
INT/INTEGER | Integer between -2,147,483,648 and 2,147,483,647 | 4 |
BIGINT | Large integer between -9 quintillion to +9 quintillion | 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src: https://www.javatpoint.com/template-pattern | |
public interface Base { | |
boolean supports(EventModel event); | |
void apply(EventModel event); | |
} | |
// All different types of classes can implement this Base. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Tap do | |
defmacro tap(tapped_value, do: yield) do | |
quote do | |
var!(t) = unquote(tapped_value) | |
unquote(yield) | |
var!(t) | |
end | |
end | |
defmacro tap(tapped_value, :return, do: yield) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DefaultModule do | |
@callback hello(any()) :: any() | |
defmacro __using__(_opts) do | |
quote do | |
@behaviour DefaultModule | |
def hello(:a) do | |
:a | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy of https://gist.github.com/antonio/4586456 | |
# With a modification to collect all the branch names so we can make one git request | |
# Set DRY_RUN=1 to get an echo of the command | |
# Format that works with `git log --since`, e.g. 2018-01-01 | |
date=$1 | |
branches= | |
for branch in $(git branch -r | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do |
NewerOlder