/bin/zsh configurations

# vim bindings on the command line
bindkey -v

# color-coded ls output
alias ls=’ls -G’

# interactive rm
alias rm=’rm -i’

# http://www.zsh.org/mla/users/2005/msg00298.html: If a file reference cannot
# be expanded locally, this setting suppresses the no match error message and
# passes the ambiguous file reference as an arguement to the application.
setopt NONOMATCH

# -g option indicates an inline alias that can be used anywhere in the command
alias -g ocf=’ekashida@ocf.berkeley.edu’ # e.g. ’ssh ocf’

Posted in Shell. 1 Comment »

r instead of n when replacing ^M

I had the misfortune of working with a DOS-formatted CSV file where all the carriage returns were showing up as ^M in Vim.

I got as far as doing a search-and-replace:

:%s/^M/n/g

but all that did was give me ^@ wherever there used to be a ^M.

mpow figured out that all I needed a r (carriage return) instead of n (new line) in my search-and-replace command.

On a serendipitous note, I found an alternative method of getting non-printing ASCII characters such as ^M into my commands. The key sequence ^v^m will give you the ^M character! I no longer have to:

1. Open up my Vim command history buffer in…Vim.

2. Copy and paste the ^M character to form a command that I want to execute.

3. Save the command buffer and go into command mode.

4. Scroll through my command history and locate the newly-formed command.

5. Excecute the command.

According to SmartFTP, ^M are formed when ASCII files are transferred in binary mode, so the solution is to transfer them in ASCII mode.

/bin/bash configuration

# IBM has a good mini-tutorial on how to customize the bash prompt

# setting up a custom prompt
blue=’e[0;34m'
green='e[0;32m'
white='e[0m'

export PS1="[${blue}]t [${green}]h[${white}]:[${blue}]W[${white}]$ “

alias rm=’rm -i’
alias cp=’cp -i’
alias mv=’mv -i’
alias ls=’ls -G’

# & supresses duplicate entries
# [ t] doesn’t record any commands with a preceding space
export HISTIGNORE=”&:[ t]*:ls:[bf]g:exit”
export HISTSIZE=1000
export EDITOR=/usr/bin/vim

MacPorts on OSX

Decided to go with MacPorts instead of the alternatives because Red mentioned that the guy who wrote DarwinPorts (now MacPorts) works at Apple. Not sure if that’s a good reason, but it’s better than a coin toss.

Installation is straightforward if you follow instructions (unlike me).

I neglected to set up the shell environment beforehand, so I ran into a bit of trouble.

Here are some basic commands:

port -v selfupdate which is equivalent to apt-get update
port search <portname> which is equivalent to apt-cache search
port -v install <portname> which is equivalent to apt-get install <appname>

The following commands are self-explanatory:

port upgrade <portname>
port upgrade outdated

Subversion and CVS

Some facts I dug up while looking up differences between SVN and CVS:

  • Subversion enforces atomic transactions while CVS doesn’t. For example, if you were checking in multiple files and one of them had conflicts, CVS would allow you to commit everything except for that one file. You would then need to resolve that file’s conflicts before it can be committed. In this way, a single, logical commit may be broken down into two.
  • CVS was originally intended for versioning of text files and so versioning of other files types (Unicode, binary) is non-trivial.
  • Subversion works faster than CVS overall (at the expense of a full backup).
  • Subversion was architecturally designed with future growth and expandability in mind, whereas CVS grew in an experimental manner. Unsurprisingly, this makes CVS difficult to grow in terms of functionality.

The pros and cons of SVN and CVS can be argued all day, but for me, the last point tips the scale in favor of SVN.

Python Notes

Notes from CS169:

  • The Python null value is None.
  • Python is dynamically and strongly typed.
  • When you want to use functions defined in imported modules, you need to include the module name: module_name.function_name()
  • Comma-delimited arguments to print in Python prints all the arguments delimited by a space.
  • Python does not allow in-line assignment, so there is no chance of accidentally changing the value of a variable you meant to use in a comparison.
  • When a module is imported, the value of __name__ is its filename. When you execute the module directly, its value is __main__. This allows you to seamlessly embed a test suite right into your code.
  • Dictionary keys must be immutable. This means that a tuple, as long as its elements are immutable, may be a key.
  • is a line continuation marker.
  • Python raises an exception if you try to reference a variable that hasn’t been assigned a value.
  • To get around the strongly-typed aspect of Python, you can use string formatting using tuples.
Posted in Python. 1 Comment »

Verilog notes

  • code within begin/end blocks are executed sequentially
  • all begin/end blocks are executed in parallel
  • ‘=’ blocks and ‘<=’ is non-blocking

Segmentation Faults vs. Bus Errors

Seg faults are raised when:

  • Programs attempt to access a memory location that it doesn’t have permission to access.
  • Programs attempt to access memory in a way that is not allowed (e.g., writing to read-only).

Bus errors occur when:

  • A non-existent physical memory access attempt is encountered. A non-existent virtual memory access attempt will cause a segfault.
  • An unaligned memory address is encountered.

Screen Multi-user Mode

Suppose Bob wants to show Alice what he’s doing in his console remotely. Bob would do the following:

1. Bob would make sure that the screen binary is suid root (sudo chmod +s /usr/bin/screen on my system).

2. Bob starts screen:
screen -S <session_name>

3. Bob allows multiuser access:
^A :multiuser on

4. Bob adds Alice to the access control list:
^A :acladd alice

5. Bob then changes Alice’s permissions to read-only:
^A :aclchg alice -w "#"

6. Alice will then ssh into the machine and:
screen -x bob/<session_name>

That’s awesome.

Notes:

  • People can join your session even if you skip acladd and just do aclchg, but they won’t be able to detatch. Weird.
  • ^A * lists all participating users (as does ^A :displays)
  • Anybody in the session can broadcast a message by typing ^A :wall <message_text>

Good Times

nmap -T 5 -M 1000 -sT 192.168.0.x