tech.zpoley.net http://tech.zpoley.net quick little hacks posterous.com Fri, 09 Sep 2011 00:50:00 -0700 Simple EventMachine tail server http://tech.zpoley.net/simple-eventmachine-tail-server http://tech.zpoley.net/simple-eventmachine-tail-server

Stream tail -f over tcp/http using EventMachine.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Wed, 07 Sep 2011 22:45:00 -0700 17 days in a tmux session http://tech.zpoley.net/17-days-in-a-tmux-session http://tech.zpoley.net/17-days-in-a-tmux-session

10 tabs, 31 buffers.

Tmux

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Sun, 24 Apr 2011 11:11:00 -0700 OS X Day and Night Terminals http://tech.zpoley.net/os-x-day-and-night-terminals http://tech.zpoley.net/os-x-day-and-night-terminals

I recently found time to explore creating separate OS X Terminal styles for day and night. Here is my solution, please let me know if you have a better setup.

First, I created two different themes in iTerm2 or Terminal.

Then I created two AppleScripts called "Dayterm" and "Nightterm" below:

The AppleScripts write to both Terminal or iTerm2 OS X defaults properties. Then, I saved the AppleScripts as Applications and now I can do spotlight "Dayterm" or spotlight "Nightterm" to use one or the other. Setting the defaults shown means that opening new tabs or windows from within the opened terminal app will use the same Dayterm or Nightterm style as the one that was opened. Exporting the "SHELL_VIBE" variable allows reading the current Terminal style from other places like .vimrc for instance to further customize the terminal experience for Day or Night.

Doing all of my work in Tmux also allows me to detach my Tmux client and switch Terminal styles and re-attach to the same Tmux session in the new Terminal style.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Fri, 07 May 2010 19:14:00 -0700 Javascript: Server callback on window unload http://tech.zpoley.net/javascript-cross-browser-callback-on-window-u http://tech.zpoley.net/javascript-cross-browser-callback-on-window-u

I'm using this simple cross-browser script to send tracking information back to the server when users leave a page.

Here's an example page.

I've tested it across Safari4.0.5/MobileSafari4.0.0+/Chrome5.0.375/Firefox3.6.3 and IE 6/7/8.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Wed, 28 Apr 2010 18:59:00 -0700 Ruby Logger: Format log lines like "[H:M:S.uS]: #{log_line}" http://tech.zpoley.net/ruby-logger-format-log-lines-like-18571492950 http://tech.zpoley.net/ruby-logger-format-log-lines-like-18571492950

Much shorter log format from logger if you don't care about anything but time.

[Hour:Minute:Second.Microsecond]: Log message

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Wed, 07 Apr 2010 22:35:00 -0700 Python subprocess http://tech.zpoley.net/python-subprocess http://tech.zpoley.net/python-subprocess

I thought this was cool because it made writing a quick test for my simple UDP server really clean and easy. What I needed to do was spawn another process to run alongside my script. In this case it was this subprocess that I wanted to test. Python subprocess made this really easy.

The script starts the udps server in a child process using subprocess.Popen and then sends a UDP datagram to the udps server, which gets written to the server log file. The test verification is the printed content of the udps.log file created by the udps server subprocess, and then subprocess.Popen.kill is a nice simple way to end the udps process.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Wed, 07 Apr 2010 22:03:00 -0700 Simple C UDP logging server http://tech.zpoley.net/simple-c-udp-logging-server http://tech.zpoley.net/simple-c-udp-logging-server

I've been using and liking this simple UDP server setup to receive and log stats data from iPhone apps. I'm running this simple UDP server (udps), and using the following code to send UDP datagrams from iPhone apps:

The benefits of this setup are no waiting client side, and low overhead server side (just write to a log file to process later). UDP is unreliable so I could be missing a few datagrams, but I'm just sending stats that are nice to have but not necessary. I process the entire log every once in a while, and stream it back over http to analyze the incoming results in real-time.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley
Wed, 31 Mar 2010 21:55:00 -0700 Accessing script src CGI params in Javascript http://tech.zpoley.net/accessing-src-cgi-params-in-javascript http://tech.zpoley.net/accessing-src-cgi-params-in-javascript

This has come up a few times now as a way to avoid server side coding and use Javascript more dynamically based on the CGI parameters passed in the src attribute of the <script> tag.  This script has been cross-browser tested in Chrome5+/Safari4+/FF3.6+/IE6+.

The way this script works is:

  • create/increment global index of this script in the DOM
  • find all script tags currently in the DOM
  • count occurences of this script using the sentinel __JSCGI=1
  • assign scriptElement variable to the current instance of the script
  • parse CGI parameters from src attribute

Being setup this way also allows the script to be included in the DOM multiple times specifying different CGI parameters to determine different functionality for the script. 

A simple demo can be found here using the cgi.js file here.

If you have a better way of doing this please do share.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/400918/zp-square-inv-128.png http://posterous.com/users/KDBAPuosoh Zachary Poley zpoley Zachary Poley