TextMate rsync Bundle

February 11th, 2009

I wrote a simple bundle a few months ago for TextMate that rsync’s your project directory with a remote host.  I use it on projects that aren’t under version control to keep myself from having to open a terminal or FTP client to upload changed files.

http://github.com/jpriddle/tm-rsync

Just follow the instructions on github and you should be all set.

PHP Script To Delete All WordPress Tables

February 11th, 2009

I’ve had to do this a few times when I wasn’t able to just drop the entire database, so I threw together a small PHP script that will do it for you.  Get it on Pastie.

Just add your username, password, and database name and save it as wp_delete.php. If you have shell access you can run php wp_delete.php. Otherwise upload it to your site and pull up http://yoursite.com/wp_delete.php. Make sure you delete this file if you upload it to your site!

*Note: If you used something other than wp_ as your table prefix, make sure to edit the script accordingly.

New Blog

February 10th, 2009

Since I haven’t done much with this domain in a while, I’ve decided to turn it into a blog.  I’m a busy little ninja, maybe there will be some useful stuff here someday.

Asterisk Manager Commands

July 26th, 2008

I’ve been playing around with the Asterisk Manager lately (which is pretty damn cool, if you ask me).

There doesn’t seem to be a list of all the commands available on voip-info right now, so I’m posting these here for my own reference.

These are the Manager commands available on Asterisk 1.4
AbsoluteTimeout: Set Absolute Timeout (Priv: call,all)
AgentCallbackLogin: Sets an agent as logged in by callback (Priv: agent,all)
AgentLogoff: Sets an agent as no longer logged in (Priv: agent,all)
Agents: Lists agents and their status (Priv: agent,all)
ChangeMonitor: Change monitoring filename of a channel (Priv: call,all)
Command: Execute Asterisk CLI Command (Priv: command,all)
DBGet: Get DB Entry (Priv: system,all)
DBPut: Put DB Entry (Priv: system,all)
Events: Control Event Flow (Priv: <none>)
ExtensionState: Check Extension Status (Priv: call,all)
Getvar: Gets a Channel Variable (Priv: call,all)
Hangup: Hangup Channel (Priv: call,all)
ListCommands: List available manager commands (Priv: <none>)
Logoff: Logoff Manager (Priv: <none>)
MailboxCount: Check Mailbox Message Count (Priv: call,all)
MailboxStatus: Check Mailbox (Priv: call,all)
MeetmeMute: Mute a Meetme user (Priv: call,all)
MeetmeUnmute: Unmute a Meetme user (Priv: call,all)
Monitor: Monitor a channel (Priv: call,all)
Originate: Originate Call (Priv: call,all)
Park: Park a channel (Priv: call,all)
ParkedCalls: List parked calls (Priv: <none>)
PauseMonitor: Pause monitoring of a channel (Priv: call,all)
Ping: Keepalive command (Priv: <none>)
PlayDTMF: Play DTMF signal on a specific channel. (Priv: call,all)
QueueAdd: Add interface to queue. (Priv: agent,all)
QueuePause: Makes a queue member temporarily unavailable (Priv: agent,all)
QueueRemove: Remove interface from queue. (Priv: agent,all)
Queues: Queues (Priv: <none>)
QueueStatus: Queue Status (Priv: <none>)
Redirect: Redirect (transfer) a call (Priv: call,all)
SetCDRUserField: Set the CDR UserField (Priv: call,all)
Setvar: Set Channel Variable (Priv: call,all)
SIPpeers: List SIP peers (text format) (Priv: system,all)
SIPshowpeer: Show SIP peer (text format) (Priv: system,all)
Status: Lists channel status (Priv: call,all)
StopMonitor: Stop monitoring a channel (Priv: call,all)
UnpauseMonitor: Unpause monitoring of a channel (Priv: call,all)
UserEvent: Send an arbitrary event (Priv: user,all)
WaitEvent: Wait for an event to occur (Priv: <none>)

OS X: Fixing the Terminal

June 10th, 2008

This might not be a problem for everyone, but I got used to using home, end, page up, and page down to navigate through the command line and documents through the console.  I was quite suprised to see that these seemingly basic features were missing from OS X’s Terminal.app.

After a ton of Googling, I came across this article which pointed me in the right direction.

First, I created a file called ~/.inputrc which contains the following:

# allow the use of the Home/End keys
“\e[1~”: beginning-of-line
“\e[4~”: end-of-line

# allow the use of the Delete/Insert keys
“\e[3~”: delete-char
“\e[2~”: quoted-insert

Next, under Terminal > Preferences > Keyboard, find Home, End, Page Up, and Page Down, and enter the following values for each.  Make sure to choose ‘Send string to shell:’ as the action.  Note: Do not type the literal characters.  Use the delete one character button to delete the values there.

Home: \033[1~  (Type: Ctrl+[, [, 1, ~)
End: \033[4~  (Type: Ctrl+[, [, 4, ~)
Page Up: \033[5~  (Type: Ctrl+[, [, 5, ~)
Page Down: \033[6~  (Type: Ctrl+[, [, 6, ~)

Once you’ve done this, just restart Terminal.app, and you’re golden.

* Special thanks to the owner of the blog above who literally saved the day for me on my Mac.

Asterisk on Ubuntu Server

March 4th, 2008

I know I’ve blogged this before, but these are the steps I took most recently to get Asterisk running on a fresh Ubuntu Server (Dapper) installation.  The instructions will also work on Feisty or Gutsy server.

# apt-get install linux-headers-`uname -r` build-essential libssl-dev libncurses5-dev libspeex-dev sox sox-dev
# mkdir /usr/src/asterisk
# cd /usr/src/asterisk
# wget http://downloads.digium.com/pub/asterisk/releases/asterisk-1.4.18.tar.gz
# wget http://downloads.digium.com/pub/zaptel/zaptel-1.4.9.2.tar.gz
# tar -vzxf zaptel-1.4.9.2.tar.gz
# cd zaptel-1.4.9.2.tar.gz
# ./configure
# make
# make install
# make config
# cd ..
# tar -vzxf asterisk-1.4.18.tar.gz
# cd asterisk-1.4.18
# ./configure
# make
# make install
# asterisk
# asterisk -r

If all goes well, you should see the Asterisk console.

Note: I am not 100% sure which repos have the packages mentioned, but I had the universe and multiverse repos added so my sources.list for apt.

Random Date Helpers

February 17th, 2008

I wrote these as helpers for a project I’m making with CodeIgniter, but you can use them in any application.

// Converts n seconds to an HH:MM:SS time stamp
function seconds_to_time($seconds)
{
  $out = '';
  $hours = '';
  $mins = '';
  $secs = '';

  $mins = str_pad(floor($seconds / 60), 2, '0', STR_PAD_LEFT). ':';

  if ($mins > 60)
  {
    $hours = floor($mins / 60). ':';
    $mins = str_pad(($mins - 60), 2, '0', STR_PAD_LEFT). ':';
  }

  $secs = str_pad(floor($seconds % 60), 2, '0', STR_PAD_LEFT);

  return $hours.$mins.$secs;
}

// ------------------------------------------------------------------------

// Returns an array HTML for 3 dropdown boxes for month/day/year
// Optional suffix can be appended to each elements HTML name
function date_dropdown($suffix = '')
{
  $out = array('month', 'day', 'year');
  $months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July',
    'August', 'September', 'October', 'November', 'December');

  // Month dropdown
  $out['month'] = "<select name="month$suffix">n";
  foreach ($months as $k => $v)
  {
    $out['month'] .= "<option value="". str_pad($k, 2, '0', STR_PAD_LEFT) .'"'.
             (str_pad($k, 2, '0', STR_PAD_LEFT) == date('m') ? ' selected="selected"' : '').
             ">$v</option>n";
  }
  $out['month'] .= "</select>n";

  // Day dropdown
  $out['day'] = "<select name="day$suffix">n";
  for ($i = 1; $i < = 31; $i++)
  {
    $out['day'] .= "<option value="". str_pad($i, 2, '0', STR_PAD_LEFT) .'"'.
            ($i == date('d') ? ' selected="selected"' : '').
            ">$i</option>n";
  }
  $out['day'] .= "</select>n";

  // Year dropdown
  $out['year'] = "<select name="year$suffix">n";
  for ($y = 2006; $y <= date('Y'); $y++)
  {
    $out['year'] .= "<option value="$y"".($y == date('Y') ? ' selected="selected"' : '').
            ">$y</option>n";
  }
  $out['year'] .= "</select>n";

  return $out;
}

Kate Project Manager Plugin on Kubuntu

February 5th, 2008

It was a pain, but this ought to work:

# apt-get install kde-devel automake1.9
# tar -vjxf /home/priddle/Desktop/projectmanager-0.1.2-24.tar.bz2 -C /usr/src/
# cd /usr/src/projectmanager/
# ./configure --prefix=/usr
# make
# make install

I just did a clean install and I’m determined to keep it that way. So I removed these packages after:
cervisia cvs gettext-kde hspell kappfinder kapptemplate kbabel kbugbuster
kcachegrind kde-core kde-devel kdebase kdebase-dev kdelibs4-dev kdesdk
kdesdk-kfile-plugins kdesdk-kio-plugins kdesdk-misc kdesdk-scripts kmtrace
kompare kpager kpersonalizer kspy ktip kuiviewer kunittest libacl1-dev
libapr1 libaprutil1 libarts1-dev libartsc0-dev libasound2-dev libaspell-dev
libattr1-dev libavahi-qt3-dev libbz2-dev libcvsservice0 libidn11-dev
libjasper-dev libkonq4-dev liblua50-dev liblualib50-dev libogg-dev
libopenexr-dev libpcre3-dev libpcrecpp0 libsasl2-dev libssl-dev libsvn1
libtiff4-dev libtiffxx0c2 libvorbis-dev libxml2-utils libxslt1-dev lua50
poxml qt3-designer subversion umbrello

Code Folding in Vim

July 5th, 2007

So I learned yet another awesome feature in vim today - code folding.

For those of you who don’t know what I’m talking about, code folding lets you shrink the contents of multiple lines of code into 1 line.  A lot of the better code editors out there do it, like Dreamweaver and ZendStudio.  It’s a handy feature when you have scripts with hundreds of lines of code.

There are several ways you can fold a portion of code in vim. You could type 10:fold for instance, and the 10 lines under the cursor would be folded.  You could also specify the start and end lines manually with :[start line],[end line]fold

An easy way I saw to do this, is to use Shift+V in command mode. This will let you highlight lines of code. So it’s as simple as pressing Shift+V then the down arrow until you’ve highlighted a section of code. Then you can press zf to fold (or type in :fold).

Cool right? There’s one more thing I did to keep these folds from session to session - normally folds will disappear after you close vim unless you create what is called a view. I found a page on vim.org that explains how to do this automatically. Just add these lines into your ~/.vimrc file:

autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview

This will save your folds when you exit a document and load them when you open it.

Happy folding!

tar over ssh

July 2nd, 2007

I figured out this easy way to make a backup over ssh.

ssh remoteserver “cd source/dir && tar -vzcf - .” > yourbackup.tgz

You can also do this [not sure if it really makes a difference]

tar -vzcf - . | ssh remoteserver “cat > yourbackup.tgz”