Skip to content

Instantly share code, notes, and snippets.

View michaelminter's full-sized avatar

Michael Minter michaelminter

View GitHub Profile
@michaelminter
michaelminter / mac_terminal_keys
Last active August 29, 2015 13:59
Mac terminal shortcut keys #console
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
@michaelminter
michaelminter / regex_vars.rb
Created December 12, 2013 21:39
Get matched content from a regex # ruby search string
v = 'foobar'
if v =~ /^foo(bar)$/
puts $1 # => "bar"
end
@michaelminter
michaelminter / grep.sh
Created December 10, 2013 16:39
One of the easiest methods of locating text contained within a file on a computer running Linux is to use the grep command. Below is a basic example of a command used to locate any html file containing the word help. # linux mac command line find
grep "help" *.html
@michaelminter
michaelminter / numeric.rb
Created November 27, 2013 19:45
Get word duration from time in seconds Extend Numeric so that you can invoke the method on any numeric class (Fixnum, Bignum, or in your case Float).
class Numeric
def duration
secs = self.to_int
mins = secs / 60
hours = mins / 60
days = hours / 24
if days > 0
"#{days} days and #{hours % 24} hours"
elsif hours > 0
@michaelminter
michaelminter / list directory size.sh
Created November 26, 2013 18:57
List size of directories in human readable format #linux #mac
du -sh ./*/
# could probably also
du -sh ./*/ | sort -n
@michaelminter
michaelminter / An-Anonymous-Pen.markdown
Created November 17, 2013 16:48
A Pen by A Non Ymous.
@michaelminter
michaelminter / git_log_before.sh
Created November 14, 2013 16:56
Show today and yesterday git activity # commits log
# git today
git config --global alias.today '!git log --since=midnight --author="$(git config user.name)" --oneline'
# git yesterday
git config --global alias.yesterday '!git log --graph --all --since="day.before.yesterday.midnight" --until=midnight --author="$(git config user.name)" --oneline'
@michaelminter
michaelminter / string_to_hash.rb
Created November 13, 2013 21:56
Turn CSV delimited text string into hash
# tested on Ruby 1.9.3
CSV.parse(response.body, { :headers => true, header_converters: :symbol, converters: :all }).collect { |row| Hash[row.collect { |c,r| [c,r] }] }
@michaelminter
michaelminter / scp.md
Created November 8, 2013 21:11
scp examples # command line, linux, mac

#Example syntax for Secure Copy (scp)

##What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

###Examples

Copy the file "foobar.txt" from a remote host to the local host