Samuel Kaufman ( Web Developer / Code Monkey )

3Feb/120

Dev Toolkit review – Mac

  • gitx is a Graphical git history/commit viewer for OSX, much like gitk I'm told.
  • iterm2 is Terminal+ basically. Download the latest version, not stable, and you'll get tiling panes: drag and drop your terminal windows into nicely tiled splits. Also, seems to work out of the box with passthrough mouse events, good for selecting tmux panes.
Tagged as: , , No Comments
28Jan/123

When to use App::Perlbrew; Installing perl from source.

App::perlbrew is a great tool to help you manage multiple perl versions on your system. The best use case for this is authors who wish to test their code against multiple versions of perl.

There is, however, a much more common reason for wanting multiple versions of perl:
wanting a later version than your system perl.
Be it for more robust unicode support, or other new features/bug fixes, you're better off with later versions of perl than earlier.

For some reason, Perlbrew is often recommended for this use case as well.
I've gone through the install several times and I can honestly say it was far easier to just install perl from the tarball.
Now granted, My use case might be slightly more complex than the norm- I was installing perl for the usage of several users and I have sysadmin privileges on the machines-
though nowadays with virtual machines almost as cheap as managed hosting I doubt it.

If installing perl was devilishly tricky I could understand why you'd need a 3rd party tool to help you with it (maybe it is on other system configs?), but all it takes is:

sh Configure -de -Dprefix=/opt/perl
make
make test
make install

I'm installing perl into /opt/perl here, you can leave off the -Dprefix= if you want to install to /usr/local.
Read the INSTALL file for more detailed instructions.

After perl is installed, stick a export PATH=/opt/perl/bin:$PATH in your .bashrc or .profile or whatever so the system will find the newly installed version of perl rather than the system version.

Tagged as: , , 3 Comments
17Dec/110

Vim – File Bookmarks, mA-Z0-9

I've used vim for about 4 years. Like other vim users, I still don't use (or even know about) all the features of the program. Most features for me fall into the category of stuff that I'll probably never need, but recently I learned of a killer feature ( from reddit.com/r/vim )that I can't believe I've done without: inter-file bookmarks. ( somebody help me come up with a better name )

[ :help m ] to read the official help on marking

I've used regular bookmarks within files for quite some time:
I'm editing some method, realize I need to fix another method, so I bookmark my position by going into "normal" mode (ESC or ctrl-[) and hitting ma:
m for mark and a for save as mark a.
I edit my stuff, then jump back to that spot with 'a.
If I need a second bookmark, I use mb c,d,e etc.
This is very useful by itself.

When instead of using lowercase, you use the uppercase letters or numbers; A-Z or 0-9, your bookmarks keep track of the file they're in as well.

So when you're editing a template, then you have to jump to some controller level editing and back, you can bookmark the original file with mA instead of opening up a split or tab and leaving that open.
Very useful, especially because you can close vim, and next time you open it your bookmarks are still there.

1Nov/110

tests

t/sheeeeei.t .................... 12293482934082304/?

Filed under: Uncategorized No Comments
11Oct/115

View Source in Vim – Perl

Edit October 12, 2011-
A couple people pointed out in the comments a nice feature provided by the perl filetype plugin that also can view source on a module.

installation:
make sure
filetype plugin on

is in your .vimrc.
If you prefer gf to open in a new split, add
nnoremap gf :sp<CR>gf

in there as well.
if your files aren't getting autodetected as perl (.t files, other cases as well I'm sure)
you can always :setfiletype perl.


Synopsis:
Highlight a module in vim, hit your custom keybinding (F2 in my case), and the module source opens in a new buffer.

requirements: pmpath

vmap <F2> y :new \| :e `pmpath <C-r>"`<CR>

Installation:
Add the above to your ~/.vimrc
:so ~/.vimrc

Tagged as: , , , 5 Comments
9Jun/110

Understanding Linux ps – STAT

$ps uxf
Most of the output is sane, you can sort of grasp some of these numbers are percentages, others are decimals. STAT is not one of those columns.
Excerpted from $ man ps :
PROCESS STATE CODES

Here are the different values that the s, stat and state output specifiers
(header "STAT" or "S") will display to describe the state of a process.
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

Filed under: Uncategorized No Comments
8May/110

checking out Natural Language Tool Kit [ python nltk ]

OK Python, it's been awhile, lets see what you got.
lets search for 'file open' to see how to open a file.
OK That clearly didn't work. hrm.
Hows about io?
So it seems search sucks here.
here we go.

My interpretation of one of the tutorials:

import nltk
#from urllib import urlopen
#url = "http://www.gutenberg.org/files/2554/2554.txt"
#raw = urlopen(url).read()
crime_and_punishment = ""
with open('crimeAndPunishment','r') as crime_and_punishment_f:
  crime_and_punishment = crime_and_punishment_f.read()
tokens = nltk.word_tokenize(crime_and_punishment)
print tokens[:10]

First impressions:
nice default stringification of arrays. Pretty easy to pick up.

29Apr/113

Lazy sprintf in perl

sub _ { sprintf( shift, @_ ) }

sprintf feels like too long a word sometimes.

die _("you're %s is %s",'hair','on fire');

Tagged as: , , 3 Comments
26Apr/114

Bash aliases + Perl One Liners: YAML Syntax Checker

I was looking for a program I used to have that validated the syntax of a yml file. Couldn't find it, so I wrote my own:

alias yml="perl -MYAML -e 'YAML::LoadFile(shift) && print qq(file parsed.\n) '"

(required: YAML)

now I can


$ yml etc/blah.yml

and tab completion works for the filename, upholding.

Code breakdown:

"perl -MYAML -e 'YAML::LoadFile(shift) && print qq(file parsed.\n) '"

-MYAML : load the YAML module

-e : execute the next argument inline

YAML::LoadFile(shift) : shift an element off the default array (any args passed to the command) and load it up. Will die with an error if invalid syntax is detected, otherwise will return a hash of the parse file-
-which evaluates to true, so perl has to interpret the other side of the && which is

print qq(...) : act like double quotes. Easier to read than ' \"\" '.

What are your aliases?

14Apr/111

EC2 retrieving data (ids etc) for the instance you’re on

curl http://169.254.169.254/latest/meta-data/
gives you useful data on your currently running instance:

ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
kernel-id
local-hostname
local-ipv4
mac
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
ramdisk-id
reservation-id

So, for example:

$ curl http://169.254.169.254/latest/meta-data/hostname
domU-etc-etc.compute-1.internal

Tagged as: , , , 1 Comment