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
Regex
"(\$)([0-9]*),?([0-9]*),?([0-9]*)(\.?)([0-9]*+ *)"
Replace
"$1$2$3$4$5$6"
Finds "$999,999,999.99 " literal and replaces it with "$999999999.99 "
@pwpearson
pwpearson / sed cheatsheet
Created January 15, 2018 16:05 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@pwpearson
pwpearson / postgres-cheatsheet.md
Created August 2, 2017 19:04 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@pwpearson
pwpearson / markdown.md
Created July 25, 2017 14:43 — forked from jonschlinkert/markdown-cheatsheet.md
A better markdown cheatsheet. I used Bootstrap's Base CSS documentation as a reference.

Typography

Headings

Headings from h1 through h6 are constructed with a # for each level:

# h1 Heading
## h2 Heading
### h3 Heading
@pwpearson
pwpearson / oneliners.scala
Created March 29, 2017 16:15 — forked from pgk/oneliners.scala
Scala one-liners
val factorialOfFive = {1 to 5}.toList.reduceLeft(_*_)

10 Scala One Liners to Impress Your Friends

Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.

Updated: June 17, 2011 - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.

1. Multiple Each Item in a List by 2

The map function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to o

@pwpearson
pwpearson / PPT.applescript
Created February 3, 2017 15:46 — forked from botanicus/PPT.applescript
Launch iTerm2 session with 3 split windows and run commands in them.
-- Find more at http://iterm.sourceforge.net/scripting.shtml
launch "iTerm"
tell application "iTerm"
activate
-- ssh in split panes to my varnish stack
set myterm to (make new terminal)
tell myterm
#!/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
@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
@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(