Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Displaying Session and Application variables

Often when using ASP or Active Server Pages you will find it necessary to do some troubleshooting. Below is some neat code you can run that will show you all the current Session and Application variables and really give you a good idea of what sort of information is being saved in them. At the bottom of this page we also show you a way to erase/clear all this information all at once.

<font face=arial size=1>
Session Variables - <% =Session.Contents.Count %> Found<br><br>
<%
Dim item, itemloop
For Each item in Session.Contents
  If IsArray(Session(item)) then
    For itemloop = LBound(Session(item)) to UBound(Session(item))
%>
<% =item %>  <% =itemloop %> <font color=blue><% =Session(item)(itemloop) %></font><BR>
<%
    Next
  Else
%>
<% =item %> <font color=blue><% =Session.Contents(item) %></font><BR>
<%
  End If
Next
%>

<hr>

Application Variables - <% =Application.Contents.Count %> Found<br><br>
<%
For Each item in Application.Contents
  If IsArray(Application(item)) then
    For itemloop = LBound(Application(item)) to UBound(Application(item))
%>
<% =item %>   <% =itemloop %> <font color=blue><% =Application(item)(itemloop) %></font><BR>
<%
    Next
  Else
%>
<% =item %> <font color=blue><% =Application.Contents(item) %></font><BR>
<%
  End If
Next
%>
</font>

Additionally, here is some handy code you can run that will wipe that information clean.

<%
Session.Abandon
Application.Contents.RemoveAll()
%>

Record terminal sessions with ttyrec

See ttyrec: a tty recorder and man script (alternative)

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export IFS=$' \t\n'

cd ~/Desktop
curl -L -O http://0xcc.net/ttyrec/ttyrec-1.0.8.tar.gz
tar -xzf ~/Desktop/ttyrec-1.0.8.tar.gz
cd ttyrec-1.0.8
make


# create /usr/local/bin
/usr/bin/sudo /bin/mkdir -p /usr/local/bin
/usr/bin/sudo /usr/sbin/chown root:wheel /usr/local /usr/local/bin
/usr/bin/sudo /bin/chmod 0755 /usr/local /usr/local/bin

# copy ttyrec, ttyplay and ttytime to /usr/local/bin
/usr/bin/sudo /bin/cp -i ~/Desktop/ttyrec-1.0.8/ttyrec /usr/local/bin
/usr/bin/sudo /bin/cp -i ~/Desktop/ttyrec-1.0.8/ttyplay /usr/local/bin
/usr/bin/sudo /bin/cp -i ~/Desktop/ttyrec-1.0.8/ttytime /usr/local/bin

ls -l /usr/local/bin/{ttyrec,ttyplay,ttytime}


ttyrec -h     # usage: ttyrec [-u] [-e command] [-a] [file]

ttyrec -a ~/Desktop/session.tty

echo hello world 1
ls
exit


ttyplay ~/Desktop/session.tty -s2


ttyrec -a ~/Desktop/session.tty

echo hello world 2
ls -l
exit


ttyplay ~/Desktop/session.tty -s2
[+]     # speed up playback


ttytime ~/Desktop/session.tty


gzip ~/Desktop/session.tty
gunzip < ~/Desktop/session.tty.gz | ttyplay

Disconnect Windows 2000 RDP session from command line

I use SSH to gain access to my Windows 2000 command line, so that will be reflected in the below steps.


Step #1: Connect to the server if you are not sitting at it
ssh username@win2000server -i privatekey

Step #2: Find out which sessions are currently active
query session

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
 rdp-tcp#7         fakeuser                  1  Active  rdpwd

Step #3: We want to kill the connection with an ID of 1 (we can tell by the username and that it is active)
tsdiscon 1 /v

Disconnecting sessionID 1 from sessionname RDP-Tcp#7

That's it :) Easy eh?

YAML parameters, session, etc. in Rails functional tests

This lets you embed YAML in your functional tests, for when you have complex form posts you want to mock out.

  post :process_checkout, YAML.load(<<-END.gsub(/^\s*\|/, "")).symbolize_keys
  |---
  |card:
  |  number: "4242424242424242"
  |  month: 8
  |  year: 2010
  |  first_name: Test
  |  last_name: Customer
  |  type: visa
  END