in LimeChat.app/Contents/Resources/logrenderer.rb around line 419… WFM. IANAL. YMMV. RTFM. OMGWTF. WTL. GTFO. ETC.
words.each do |w|
next if w.empty?
s = body
offset = 0
# <edit was="rex = Regexp.new(Regexp.escape(w), true)">
rex = Regexp.new(w, true)
# </edit>
while rex =~ s
# <edit>
begin
# </edit>
left = $~.begin(0)
right = $~.end(0)
pre = $~.pre_match
post = $~.post_match
ok = true
if exact_word_match
if !pre.empty? && alphabetic?(w.first_char) && alphabetic?(pre.last_char)
ok = false
elsif !post.empty? && alphabetic?(w.last_char) && alphabetic?(post.first_char)
ok = false
end
end
if ok
keywords < < { :pos => offset+left, :len => right-left }
end
s = post
offset += right
# <edit>
rescue
next
end
# </edit>
end
end
We use dirname() a lot in php to make relative paths work from multiple locations like so. The advantages are many:
require dirname( dirname( __FILE__ ) ) . '/required-file.php';
$data = file_get_contents( dirname(__FILE__).'/data/info.dat');
But in bash we often dont do the same thing, we settle for the old standby “../”. Which is a shame because unless your directory structure is set up exactly right, and you have proper permissions, and you run the command from the right spot, it doesnt work as planned. I think part of the reason is that its not obvious how to reliably get a full path to the script from inside itself. Another reason is that ../ is shorter to type and easier to remember. Finally there’s always one time scripts for which this methodology is overkill. But if you’re planning to write a script which other people will (or might) be using, I think it’s good practice to do it right. Googling for things you’d think to search for on this subject does not yeild very informative results, or incomplete (incorrect) methods… so… here’s how to do the above php in bash:
source $(dirname $(dirname $(readlink -f $0)))/required-file.sh
data=$(cat $(dirname $(readlink -f $0))/data/info.dat)
Hope this helps someone
As a side note, the OSX readlink binary functions differently. You’ll want to use a package manager to install gnu coreutils, and iether use greadlink, or link greadlink to a higher precedence location on your $PATH (I have /opt/local/bin:/opt/local/sbin: at the beginning of my $PATH)
I work in linux a lot… not bsd. So the OSX (bsd style) implementation of sed really throws me for a loop when I go text-file-spelunking, whats worse is that my scripts using sed aren’t portable between the two OSs.
A quick googling this morning landed me here: http://wiki.octave.org/wiki.pl?OctaveForMac which gives perfectly good instructions on installing sed. except it didnt work. I grabbed the latest version of sed (4.1.5) and got the error
sed: 1: "install_sh=/Users/apoka ...": command i expects \ followed by text
sed: 1: "install_sh=/Users/apoka ...": command i expects \ followed by text
Ironic, huh? Well taking a guess that at some point sed hadcome to depend on its own functionality to configure itself I jumped back a version… Figuring i replace BSD sed with an out of date GNU sed, and then use the old GNU sed to build the new GNU sed. Which worked great. I Installed first sed-3.0.2, and then 4.1.5 in this manner:
./configure --prefix=/usr/ --with-included-regex --with-included-gettext && make && sudo make install
I’m happy with my -r again…
# date | sed -r s/'[0-9]'/'?'/g
Thu Apr ?? ??:??:?? PDT ????
OS X |
Posted by apokalyptik
Dec
31
2007
First of all I did not “upgrade” I backed up (using iBackup 6.2,) then booted into the installation DVD (restart, hold C for a long time) and then entered the disk utility, formatted my disk, and installed fresh. After rebooting and finishing my installation, I re-downloaded iBackup, and restored selected applications (and their settings,) My system settings, and my home directory.
The bad:
iBackup does not backup dot folders in the root of a backed up folder! It backed up .svn directories in my svn checkouts, but not (for example) my .ssh or .subversion folders in ~/. For the vast majority of users this doesnt matter. but for developers and admins (I happen to be both) this is severely annoying. Lucking I keep a backup of my .bash_profile, and my ssh rsa and dsa keys. So all is well
The good:
I was extremely happy about a lot of things in leopard!! First of all my delete button works now instead of entering “~” each time i hit it. Second subversion was installed by default (yay!) Third the builtin ssh command now supports public key authentication from ~/.ssh/ keys by default (yay!)
Thats all. My first impressions have been very good. I’m happy with the product, and these minor improvements have really made me smile. They were little annoyances, but annoyances nonetheless that hindered me every day (especially the delete key thing.) That makes the already enjoyable OSX experience that much more enjoyable. Haven’t had to use macports for anything yet!
And if they aren’t, they should be! Ajax has long been the missing link between phones as a mobile computing platform and phones as a simple messaging device. the fact is that there is a vastly larger poll of people willing to write useful web apps than useful java apps. I would also argue that it’s easier to write good web apps than java apps of the same magnitude. So with apples announcement that the iPhone will support web 2.0 standards (read AJAX) what was once a tasty looking new toy has become something more. It’s become a tasty toy with a good enough reason for the cost. I’d have to pay to break my contract with Sprint, start a contract with Cingular, buy the new iPhone, buy the wife a new phone (shared Sprint plan)…. I’m probably looking at $700-$1000 to make the switch. And I’m already thinking that its worth it. I’m going to hold off though… as long as I can stand it. I want someone to review it, I want to see how the web explosion hits Cingulars networks… I want to see how hard they are to find at first… Mostly I just want the damn phone really bad… But I’m gonna try to be a good boy and hold off… Maybe
CLI,
OS X |
Posted by apokalyptik
Jan
29
2007
This is more or less a reference for myself in the future… in case I ever need to dig this up again… It’s quite easy to make a directory info an ISO image via the command line in OSX
hdiutil makehybrid -iso -joliet -o ../myiso.iso ./