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
@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

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 / oneliners.scala
Created March 29, 2017 16:15 — forked from pgk/oneliners.scala
Scala one-liners
val factorialOfFive = {1 to 5}.toList.reduceLeft(_*_)
@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 / 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 / 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'
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 "

Months

SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0) -- First day of previous month

SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), -1) -- Last Day of previous month

SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) -- First day of this month

SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, -1) -- Last day of this month
1. Create new container
a) docker run -i -t ubuntu /bin/bash
b) docker run --name rails_dev_container -i -t ubuntu ubuntu /bin/bash
The command line flags - i -t provide an interactive shell in the new container
2. Show running docker containers ==> docker ps
3. Show list of current containers ==>
a) docker ps -a (Show all containers, both stopped and running)
b) docker ps -n x (shows the last x containers, running or stopped, ex: docker ps -n 5)

###Mount HFS & HFSPLUS (Apple Filesystem Types)

First thing first, you have to install kmod-hfs & kmod-hfsplus and hfsplus-tools.

Step 1: Import GPG Key

rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org

To install ELRepo for CentOS-7: