Friday, August 8, 2014

Parallax CSS - Giving depth to the web

keithclark parallax description

very cool intro into depth css on the web.

css3 html5


Wednesday, August 6, 2014

screen

SCREEN 

Keep all your ssh processes running despite dropped connections.

Getting in

start a new screen session with session namescreen -S <name>
list running sessions/screensscreen -ls
attach to a running sessionscreen -x
… to session with namescreen -r <name>
the “ultimate attach”screen -dRR (Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.)
detach a running sessionscreen -d <name>

Escape key

All screen commands are prefixed by an escape key, by default C-a (that's Control-a, sometimes written ^a). To send a literal C-a to the programs in screen, use C-a a. This is useful when when working with screen within screen. For example C-a a n will move screen to a new window on the screen within screen.

Getting out

detachC-a d
detach and logout (quick exit)C-a D D
exit screen“C-a : quit” or exit all of the programs in screen.
force-exit screenC-a C-\ (not recommended)

Help

See helpC-a ? (lists keybindings)
The man page is the complete reference, but it's very long.

Window Management

create new windowC-a c
change to last-visited active windowC-a C-a (commonly used to flip-flop between two windows)
change to window by numberC-a <number> (only for windows 0 to 9)
change to window by number or nameC-a ' <number or title>
change to next window in listC-a n or C-a <space>
change to previous window in listC-a p or C-a <backspace>
see window listC-a " (allows you to select a window to change to)
show window barC-a w (if you don't have window bar)
close current windowClose all applications in the current window (including shell)
kill current windowC-a k (not recommended)
kill all windowsC-a \ (not recommended)
rename current windowC-a A

Split screen

split display horizontallyC-a S
split display verticallyC-a | or C-a V (for the vanilla vertical screen patch)
jump to next display regionC-a tab
remove current regionC-a X
remove all regions but the current oneC-a Q

Scripting

send a command to a named sessionscreen -S <name> -X <command>
create a new window and run ping example.comscreen -S <name> -X screen ping example.com
stuff characters into the input buffer
using bash to expand a newline character
(from here)
screen -S <name> [-p <page>] -X stuff $'quit\r'
a full example
# run bash within screen
screen -AmdS bash_shell bash
# run top within that bash session
screen -S bash_shell -p 0 -X stuff $'top\r'
 
# ... some time later
 
# stuff 'q' to tell top to quit
screen -S bash_shell -X stuff 'q'
# stuff 'exit\n' to exit bash session
screen -S bash_shell -X stuff $'exit\r'

Misc

redraw windowC-a C-l
enter copy modeC-a [ or C-a <esc> (also used for viewing scrollback buffer)
pasteC-a ]
monitor window for activityC-a M
monitor window for silenceC-a _
enter digraph (for producing non-ASCII characters)C-a C-v
lock (password protect) displayC-a x
enter screen commandC-a :
enable logging in the screen sessionC-a H

Tuesday, August 5, 2014

Prevent bash script from executing when same script is already running

I needed to prevent my bash script from executing (duplicating) and did not want to go searching our code base...
so I searched google instead :)

Reference

pidof -x option allows for searching for scripts being executed without specifying more than the script name.

$$ is the PID for the current process.

pidof will return an array of pids. Just check if any of the PIDs are not equivalent to this one.
DONE.


#!/bin/bash

# exit if I am already running
for pid in $(pidof -x rsync.sh); do
    if [ $pid != $$ ]; then
        echo "[$(date)] : abc.sh : Process is already running with PID $pid"
        exit 1
    fi
done

# .....

Friday, August 1, 2014

Golden Gate - length of build

HOW LONG DID IT TAKE TO BUILD THE BRIDGE?

Just over four years.  Construction commenced on January 5, 1933 and the Bridge was open to vehicular traffic on May 28, 1937.

Grep for power users

I am constantly grepping old code bases, and new, for strings within files. The problem comes when I keep running into the same issues.

  • .svn
  • .git
  • .old
  • .png, jpg, jpeg, gif...
  • .bak
  • .min
I also love to have the color option and line number option, but tend to forget about it.

  • line numbers
  • file names
  • color highlighting
  • exclude binary files!
Here is the alias that I like to set in my .bash_profile...

alias grep='grep --line-number --with-filename --color --exclude="*\.min*" --exclude-dir="\.{svn,git}" --text --exclude="*\.{png,jpg,jpeg,gif,new,bak,old,~}"'

The exclude image extensions and --text (no binary) may be redundant, but I would rather be extra cautious.


Hope this helps others!