Wednesday, November 10, 2010

Use netcat as a fake server to debug http issues

I had a problem with my http server where my cookie didn't seem to be accepted by the browser and resent. To debug the issue I wanted to be able to edit the headers that were being sent back to the browser. Here is the technique I used to quickly find the issue.


# use curl to pull the raw response
# from the server and the headers that were sent back

curl -D headers2 --raw www.serverwithproblem.com > raw2.txt

# concatenate the headers and response into one file

cat headers2 raw2.txt > both2.txt

# cause netcat to listen on a specified port
# and cat your mock response to it

cat both2.txt | nc -l 8099

# netcat will sit and wait for your request
# now aim your browser at localhost:8099


After that you go to your browser at localhost:8099 and you'll get the response you set up.

Thursday, October 28, 2010

focus

I had been running some scripts, but kept getting distracted.

I found a linux script for a dialog alert, but not one for OSX, so here is my modified script for OSX.


#!/bin/bash

eval $@

if [[ $? -eq 0 ]]; then
osascript -e 'tell application "Finder"' -e "activate" -e "display dialog \"Command '$@' in $PWD completed.\"" -e 'end tell';
else
osascript -e 'tell application "Finder"' -e "activate" -e "display dialog \"Command '$@' in $PWD failed! $@\"" -e 'end tell';
fi

Thursday, September 16, 2010

Yay Conque

I just found this vim plugin called Conque that lets you run a shell inside your vim window. It looks almost perfect.

Tuesday, September 14, 2010

Copy from and Paste to Native OS X Clipboard in Vim

I was annoyed that the builtin OSX vim version on Snow Leopard could not copy to the clipboard. I grabbed this homebrew formula http://github.com/adamv/homebrew/blob/duplicates/Library/Formula/vim.rb and recompiled vim with it. I had to move the existing vim out of way for some reason and then I had a shiny new vim with clipboard support. Just "set clipboard=unnamed" in your .vimrc file.