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 *.*
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 " |
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' |
val factorialOfFive = {1 to 5}.toList.reduceLeft(_*_) |
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.
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
-- 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 |
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 |
// 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( |