Monday, July 7, 2014

Command Line Tips

Excellent Resource:
https://github.com/0nn0/terminal-mac-cheatsheet/wiki/Terminal-Cheatsheet-for-Mac-(-basics-)

$ Ctrl+A -  to send the cursor to start of the command

$ Ctrl+E - to send the cursor to the end of the command.

$ Ctrl+C - used to quit a running program in terminal

$ Ctrl U - clears the line

$ Ctrl+L - clears the screen while retaining whatever was there on the current prompt

$ Ctrl+R - and write few characters from the start of command you’re looking for


$ echo <whatever> - reads back in the terminal whatever you write

$ cat <filename> - reads the file

$ touch <filename> - creates a new file

$ head -5 output - displays content from the beginning of a file

$ tail -5 output - displays the last five lines from the file ‘output’


$ history | grep "myarticle.txt"

$ rm -rf dirname - to force remove a directory and it's contents

$ ! - runs a previously run command


$ jobs - lists all the commands running in the background !

$ ps - displays a list of the processes you’ve launched

$ fg - bring a specific job back to the foreground

$ kill %<job-number> kills a process by it's job-number in the list or

$ kill<PID> kill a process by is process id (PID) 1234




sudo lsof -i - "list open files", which is used in many Unix-like systems to report a list of all open files and the processes that opened them. http://danielmiessler.com/study/lsof/

On a Mac you can 
$ Option + Click - to get to a specific spot in your commandline

For fun:

$ telnet towel.blinkenlights.nl 

http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/


http://www.linuxjournal.com/content/time-saving-tricks-command-line

http://www.linuxuser.co.uk/tutorials/14-command-line-tips-tricks

http://mylinuxbook.com/5-really-cool-linux-command-line-tricks/

https://linuxacademy.com/blog/linux/ten-things-i-wish-i-knew-earlier-about-the-linux-command-line-2/

Blank Terminal Window
http://www.cnet.com/news/os-x-terminal-displays-a-blank-window-instead-of-a-command-prompt/

commandline windows pwd

http://www.lemoda.net/windows/windows2unix/windows2unix.html

arparp
assignlnCreate a file link
assignln -sOn Unix, a directory may not have multiple links, so instead a symbolic link must be created with ln -s.
assocfile
atat
batch
cron
attribchown
chmod
Sets ownership on files and directories
cdcdOn Windows, cd alone prints the current directory, but on Unix cd alone returns the user to his home directory.
cdpwdOn Windows, cd alone prints the current directory.
chkdskfsckChecks filesystem and repairs filesystem corruption on hard drives.
clsclearClear the terminal screen
copycp
date
time
dateDate on Unix prints the current date and time. Date and time on Windows print the date and time respectively, and prompt for a new date or time.
delrm
deltreerm -rRecursively deletes entire directory tree
dirls"dir" also works on some versions of Unix.
doskey /h
F7 key
historyThe Unix history is part of the Bash shell.
editvi
emacs
etc.
edit brings up a simple text editor in Windows. On Unix, the environment variable EDITORshould be set to the user's preferred editor.
exitexit
Control-D
On Unix, pressing the control key and D simultaneously logs the user out of the shell.
explorernautilus
etc.
The command explorer brings up the file browser on Windows.
fcdiff
findgrep
ftpftp
helpman"help" by itself prints all the commands
hostnamehostname
ipconfig /allifconfig -aThe /all option lets you get the MAC address of the Windows PC
memtopShows system status
mkdirmkdir
moremore
less
movemv
net sessionw
who
net statisticsuptime
nslookupnslookup
pingping
printlprSend a file to a printer.
reboot
shutdown -r
shutdown -r
regeditedit /etc/*The Unix equivalent of the Windows registry are the files under /etc and /usr/local/etc. These are edited with a text editor rather than with a special-purpose editing program.
rmdirrmdir
rmdir /srm -rWindows has a y/n prompt. To get the prompt with Unix, use rm -i. The i means "interactive".
setenvSet on Windows prints a list of all environment variables. For individual environment variables, set <variable> is the same as echo $<variable> on Unix.
set Pathecho $PATHPrint the value of the environment variable using set in Windows.
shutdownshutdownWithout an option, the Windows version produces a help message
shutdown -sshutdown -hAlso need -f option to Windows if logged in remotely
sortsort
start&On Unix, to start a job in the background, use command &. On Windows, the equivalent isstart command. See How to run a Windows command as a background job like Unix ?.
systeminfouname -a
tasklistps"tasklist" is not available on some versions of Windows. See also this article on getting a list of processes in Windows using Perl
title?In Unix, changing the title of the terminal window is possible but complicated. Search for "change title xterm".
tracerttraceroute
treefind
ls -R
On Windows, use tree | find "string"
typecat
veruname -a
xcopycp -RRecursively copy a directory tree

Nesta - aggregate the posts

This is the blog for my Rails Girls Summer of Code Team The Standard Librarians.

Nesta is a Ruby CMS built with Sinatra. We were originally going to be working in Sinatra for the summer but we switched to working on the Try Ruby Standard library.

I now want to change the year to month.

http://nestacms.com/docs/recipes/adding-links-to-archived-posts

Wednesday, June 25, 2014

git - change branch to master

We have been preparing our blog to document our progress during RGSoC for what seems like an eternity.

First we wrote and entire blog from scratch in Sinatra. We realized that it really needed a lot of work to acquire all the capabilities that we wanted it to have. Stephanie found Nesta, a ruby CMS built with Sinatra. So we abandoned the work we had done and started on the new blog. It has been a few weeks now and it is almost ready. There are a lot of things you need to manually configure in Nesta.

Last night when we were working on it Steph pushed and broke the blog. I had pulled these changes into my master without realizing it. Luckily I had a branch that still worked properly so I changed that branch into the master and force pushed it with the help of these lovely and helpful directions. 
Thanks again stackoverflow.

Monday, June 23, 2014

<=> The Spaceship Operator

Perl was the first language to use <=> the Spaceship Operator.
Groovy is another language that supports it.
So does Ruby!

What does it do?
Instead of returning 1 (true) or 0 (false) depending on whether the arguments are equal or unequal, the spaceship operator will return 1, 0, or −1 depending on the value of the left argument relative to the right argument.

a <=> b :=
  if a < b then return -1
  if a = b then return  0
  if a > b then return  1

It's useful for sorting an array.

http://stackoverflow.com/questions/16600251/how-does-rubys-sort-method-work-with-the-combined-comparison-spaceship-operat

tuple
In mathematics, computer science, linguistics, and philosophy a tuple is an ordered list of elements. In set theory, an -tuple is a sequence of elements, where is a non-negative integer. There is only one 0-tuple, an empty sequence.

Sunday, June 15, 2014

Gravatar

Adding a Gravatar to our Nesta Blog Post

from
http://www.markholmberg.com/articles/gravatar-and-ruby-on-rails
The quick and dirty 
There are many configurable options that you can pass into Gravtastic. I found it quite refreshing to have a gem just work "out-of-the-box". It also has support for plain ruby if you're not using something like rails. Also, if you want to have the gravatar load on the client side, it has an option to work using javascript if your using Rails 3.1 or higher. 
Gemfile  
gem 'gravtastic'
Model 
user.rb
include Gravtastic
has_gravatar 
View 
_comment.html.haml
= image_tag @comment.user.gravatar_url

Wednesday, June 11, 2014