Skip to content

Instantly share code, notes, and snippets.

View pwpearson's full-sized avatar
🏠
Working from home

Patrick (Rick) Pearson pwpearson

🏠
Working from home
View GitHub Profile
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
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@pwpearson
pwpearson / linux
Last active August 29, 2015 14:25 — forked from jimboroberts/linux
Check if remote port is open with bash:
echo >/dev/tcp/8.8.8.8/53 && echo "open"
Suspend process:
Ctrl + z
Move process to foreground:
fg
Generate random hex number where n is number of characters:
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@pwpearson
pwpearson / tmux-cheatsheet.markdown
Created October 20, 2015 16:59 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@pwpearson
pwpearson / scalaFutureTimeout.scala
Created April 14, 2016 22:02 — forked from arschles/scalaFutureTimeout.scala
how to time out a scala future
val realFuture = Future(doRealStuff())
//timeoutFuture does a spin wait by sleeping on the thread on which it runs, so make sure the ExecutionContext
//on which it runs is multi-threaded. In an akka based environment, use a scheduler to fulfill a promise with a failure
//when the timeout duration is complete, and avoid the spin wait
val timeoutFuture = Future {
Thread.sleep(timeoutMilliseconds)
throw new TimeoutException("timeout")
}
Future.firstCompletedOf(realFuture :: timeoutFuture :: Nil)
scala> type Set = Int => Boolean
defined type alias Set
scala> Set
res0: scala.collection.immutable.Set.type = scala.collection.immutable.Set$@7a7f0991
scala> def contains(s: Set, elem: Int): Boolean = s(elem)
contains: (s: Int => Boolean, elem: Int)Boolean
scala> contains(x => x%2 == 0, 2)
@pwpearson
pwpearson / Scala Spark Window Function Example.scala
Created July 22, 2016 14:18
Spark example of using row_number and rank.
// This example shows how to use row_number and rank to create
// a dataframe of precipitation values associated with a zip and date
// from the closest NOAA station
import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.functions._
// mocked NOAA weather station data
case class noaaData(zip:String,station:String,date:Long,value:String=null,distance:Int)
val t = Seq(
@pwpearson
pwpearson / Spark-Notebook Keyboard Shortcuts.md
Last active July 27, 2016 00:19
sparkNotebookVersion-0.6.3

Keyboard shortcuts

The Spark Notebook has two different keyboard input modes. Edit mode allows you to type code/text into a cell and is indicated by a green cell border. Command mode binds the keyboard to notebook level actions and is indicated by a grey cell border.

####MacOS modifier keys

⌘: Command ⌃: Control
⌥: Option ⇧: Shift
↩: Return ␣: Space
#!/bin/bash
read -r -d '' script <<'EOF'
on run argv
tell application "iTerm"
activate
set myterm to (make new terminal)
tell myterm
launch session "Default"
tell the last session
repeat with arg in argv