Skip to content

Instantly share code, notes, and snippets.

View jm2242's full-sized avatar

Jonathan Mares jm2242

View GitHub Profile
@jm2242
jm2242 / 0_reuse_code.js
Created May 21, 2016 22:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
def number_needed(a, b):
dictA = {}
dictB = {}
for c in a:
if c in dictA:
dictA[c] += 1
else:
dictA[c] = 1
for c in b:
# Definition for an interval.
# class Interval(object):
# def __init__(self, s=0, e=0):
# self.start = s
# self.end = e
class Solution(object):
def merge(self, intervals):
"""
:type intervals: List[Interval]
#!/bin/python
import sys
def isCavity(grid, coordinate):
(r, c) = coordinate
value = grid[r][c]
maxRow = len(grid) - 1
@jm2242
jm2242 / latency.txt
Created December 8, 2017 21:10 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
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
@jm2242
jm2242 / column-header.jsx
Last active February 20, 2018 20:20
Contents of Column Header Component
render() { // render method of component
//...
<div className="column-icons">
{ canHideColumns && renderHideColumnsTrigger() }
{ canSort && renderSortingIndicator() } // shows the sort icon
{ canSearch && renderSearchTrigger() } // shows the filter icon
{ canRemoveColumns && <RemoveColumnButton /> }
{ canAddColumns && <AddColumnButton }
</div>
//...
@jm2242
jm2242 / column-styles-1.styl
Created February 20, 2018 20:21
Styles for Column Header
// (contents of stylus)
ColumnIconsMargin = 6
ColumnIconsSize = 26
TotalColumnIconsWidth = 5 * (ColumnIconsSize + ColumnIconsMargin)
.column-icons
// ...
width TotalColumnIconsWidth
// ...
@jm2242
jm2242 / column-header-partial.jsx
Created February 20, 2018 20:22
Partial Solution
render() {
// ...
<div
className={
classNames(
"column-name-text",
{ "column-name-pointer": canRenameColumns }
)
}
style={{ maxWidth: `${maxWidth}px` }}
@jm2242
jm2242 / partial-solution-2.jsx
Last active February 20, 2018 20:23
Partial solution using many classes
//(contents of the React component, simplified)
render() { // render method of component
// ...
// count the number of truthy booleans
const numberOfButtons = [canAddColumns, canHideColumns, canRemoveColumns, canSearch, canSort].reduce(
(acc, showButton) => showButton ? acc+1 : acc,
0
)
<div className={
classNames(
@jm2242
jm2242 / partial-solution-3.jsx
Created February 20, 2018 20:24
Cleaner partial solution
render() { // render method of component
// ...
<div className={`column-icons-${numberOfButtons}`}
{ canHideColumns && renderHideColumnsTrigger() }
{ canSort && renderSortingIndicator() }
{ canSearch && renderSearchTrigger() }
{ canRemoveColumns && <RemoveColumnButton /> }
{ canAddColumns && <AddColumnButton }
</div>
// ...