The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for the ‘Mac OS X’ Category

OSX Lion compile screen with 256 colors

leave a comment »

Terminal now supports 256 colors. But screen is not compiled with 256, so no matter what you do in the screenrc file, you won’t get 256 colors. homebrew wont install screen since OSX provides it.

This blog gives you the steps to compile, and within a minute you’ll have a 256 color screen. http://ryanwilliams.org/2010/Oct/09/gnu-screen-256-colours-mac-os-x

Written by totalrecall

November 11, 2011 at 7:40 pm

Posted in being_geeky, Mac OS X

Tagged with ,

Upgraded to OSX Lion: /etc/hosts issues – HELP

leave a comment »

Just upgraded. Most things are going fine. Alpine takes 30-60 seconds to load. fetchmail also takes a minute and then gives the following message:

gethostbyname failed for Awareness
nodename nor servname provided, or not knownCannot find my own host in hosts database to qualify it!
Trying to continue with unqualified hostname.
DO NOT report broken Received: headers, HELO/EHLO lines or similar problems!
DO repair your /etc/hosts, DNS, NIS or LDAP instead.

My /etc/hosts file is the stock one, I’ve not added any lines to it. I don’t use php.

postfix/sendmail was also not working … checked syslog and mail logs and find errors.
fatal: open database /etc/postfix/relay_password.db: No such file or directory
warning: /usr/libexec/postfix/smtp: bad command startup

I googled and found that other people are facing problems with /etc/hosts but not the same one, so don’t know what to do. Help appreciated.

Darn, even the mouse misbehaves. Can’t scroll horizontally with the scrollwheel (okay, that was the reverse scrolling culprit) and trying to select text but it deselects automatically 😦

Written by totalrecall

October 12, 2011 at 5:48 pm

Posted in Mac OS X

Pretty Print Code script (hack)

The hack presented below has been developed on a MAC OS X. It uses the TOhtml function of the Vim Editor (i use Version 7.0). It runs in HTML Mode only.

f=$1vim -f +"syn on" +"run! syntax/2html.vim" +"wq" +"q" $f

sed  -n '/<pre>/,/<\\/pre>/p' $f.html | sed 's~<pre>~<pre style="margin: 1.5em 0px; padding: 10px 10px 10px 10px; color: #333; background: #000000;color:#ffffff; font-family: monaco,monospace; font-size: 120%; border-left: solid #ccc 1px; overflow: auto;">~p' > $f

rm $f.html

Line 1. saves temp file name to a variable f.

Line 2. Invokes a vim plugin on the temporary file. Vim creates a file with an html extension.

Line 3. Extracts lines from output file between PRE tags. Then replace opening PRE tag with out own styling. This is required for me, since this blog does not allow me to modify the CSS.

Line 4. Delete the temp file created by Vim.

Note: If most of the code you post is in one language then the input file given to Vim should have that extension. That way the Vim plugin will do a more comprehensive syntax highlighting.

The other option is to detect the programming language from the first line of the temp file (assuming it has the interpreter name in it) and rename the file accordingly.

Source (please note that this program does not treat the escape character \, and WP does not print the \)

Written by totalrecall

March 1, 2007 at 1:00 pm

Posted in ecto, Mac OS X, ruby, vim

some more testing of a script that will do the code formatting

leave a comment »

I have hacked a script which converts the selected text in Ecto to the following formatted text.

while (<>) {
 $text .= $_;
}
# procedural usage
my $html = textile($text);
#print $html; <---- this would get printed in a dialog box
open ( FILE, ">$entryfile" ) or die;
print FILE $html;
close FILE;

[Update: If you look carefully, syntax highliting done by the hack above is not as comprehensive as the one done to textile.pl in this post. This is because in those cases, since the entire file went through the filter, the filter knew the programming language and could thus do a language specific highlighting. In the case of highlighting code within ecto and running the script, the filter invoked does not know the language. That can be further taken care of by examining the first line of the sample, and determining language from a <code>”#!/bin/env ruby”</code> like statement.]

However, before i fall asleep let me apologize. I notice that one entry of mine posted in the morning (inter.rb) seems to have the code intact. In that case, I pasted the code into the rich text editor. It did the required conversions. This appears to work fine.

It is only when i pasted the code into the HTML editor, in order to put the PRE and CODE tags, that i began to lose characters. So a lot of testing and time has gone waste. But i do have a neat hack ready now, and I have learned a couple of things about a couple of things.
I will share this hack tomorrow morning.

Back to sleep after a bit of reading The Northern Light. Oh, did I mention that I have mapped ^B and ^I to do bold-facing and italicizing.

COOL !!!

Written by totalrecall

February 28, 2007 at 11:13 pm

Posted in ecto, Mac OS X, ruby

Automatic hyperlinking to wikipedia and others using ecto scripting

leave a comment »

Ecto is a feature-rich desktop blogging client for Mac OS X and Windows, supporting a wide range of weblog systems, such as Drupal. It allows me to plug-in my own scripts writing in programming languages such as ruby, perl, Bash and i suppose python also.

This feature allows for some nifty stuff such as filtering the blog contents.

Lets link to a google search for our favorite blogging client now

The above text was hyperlinked using the script “inter” (source) based on how the interwiki module of drupal works. The input text was as follows:

[[w:ecto|Ecto]] is a feature-rich desktop blogging client for [[w:Mac OS X]] and Windows, supporting a wide range of weblog systems, such as [[http:drupal.org|Drupal]]. It allows me to plug-in my own scripts writing in [[w:programming languages]] such as [[w:ruby]], [[w:perl]], [[w:bash|Bash]] and i suppose [[w:python]] also.

This feature allows for some [[dict:nifty]] stuff such as filtering the blog contents.

[[w:ecto|Ecto]] inserts a hyperlink to wikipedia with ecto as the parameter, and Ecto as the display text of the hyperlink. On the other hand, [[w:ecto]] would use “ecto” both as parameter and display text.

Other current options are:

g: for google search

dict: for a m-w.com dictionary search

th: thesaurus.reference.com

http: a link

One can add more to the ruby script which does this replacement.

I shall try to post the ruby script in the next post. But cannot guarantee since blogsome is messing up code.

Written by totalrecall

February 28, 2007 at 10:34 pm

Posted in ecto, Mac OS X, ruby

Publishing code on this blog through Ecto

leave a comment »

Background: All attempts to publish some simple source code on this blog failed. Be it directly on WP or through Ecto. PRE and CODE tags made no difference. How many tags I might have to manually change, i do not know. But < and \ we certainly disappearing !

And so now, I run the code samples (sniff) through vim’s TOhtml plugin, and copy the resultant HTML here. Now I know that this has generated an AWFUL lot of code for just a few lines of ruby. I give you inter.rb:

#!/usr/bin/env ruby
file = ARGV[0];
text = File.open(file,"r").readlines.join;
urlmap = {"w" => "http://en.wikipedia.org/wiki/%s",
  "g" => "http://google.com/search?q=%s",
  "dict" => "http://m-w.com/dictionary/%s",
  "http" => "http:%s",
  "th" => "http://thesaurus.reference.com/search?q=%s"
}
text.gsub!(/\\[\\[(w+?):(.+?)\\]\\]/) { |match|
  path=urlmap[$1]
  if path == nil then
    puts "%s not found in urlmap" % $1
    match
  else
    str = $2.split('|')
    if str.size == 1 then
      str << str[0];
    end
    ('<a href="' + path + '">%s</a>') % [str[0], str[1]]
  end
}
#puts text
File.open(file, "w").puts text;

And now here is textile.pl:

#!/usr/bin/perl
# take textile text as stdin and output as html
# textile.psh < filename.html
# :%!textile.psh  (in vim)
use Text::Textile qw(textile);
my $text = "";
my $entryfile = $ARGV[0];

while (<>) {
 $text .= $_;
}
# procedural usage
my $html = textile($text);
#print $html;
open ( FILE, ">$entryfile" ) or die;
print FILE $html;
close FILE;
# OOP usage
#    my $textile = new Text::Textile;
#    $html = $textile->process($text);
#    print $html;

And finally here is the markdown plugin script:

#!/usr/bin/env ruby
# Markdown'ise things.
# Take Markdown markup on STDIN, and output HTML to STDOUT
require 'rubygems'
require 'bluecloth'
#print (BlueCloth.new STDIN.read).to_html
file = ARGV[0];
text = File.open(file,"r").readlines.join;
html = (BlueCloth.new text).to_html
File.open(file, "w").puts html;

Hope this comes through fine.
Read the rest of this entry »

Written by totalrecall

February 28, 2007 at 9:28 pm

Posted in ecto, Mac OS X, ruby

ecto and Markdown

leave a comment »

#!/usr/bin/env ruby
# Markdown'ise things.
# Take Markdown markup on STDIN, and output HTML to STDOUT
require 'rubygems'
require 'bluecloth'
#print (BlueCloth.new STDIN.read).to_html
file = ARGV[0];
text = File.open(file,"r").readlines.join;
html = (BlueCloth.new text).to_html
File.open(file, "w").puts html;

I must first admit that since ecto supports a WYSIWYG editor therefore a script that does textile or markdown filtering does not make much sense. Also, there is the possibility of the confusion being created. Thus the textile and Markdown examples are more of examples of what can be done. A more practical example is the inter.rb given somewhere in the previous post.

Anyway, that said, the above example requires ruby, rubygems and the BlueCloth gem to be installed. If you are running Unix or Mac OS X (which you should be), you would have ruby. Install rubygems, and then install BlueCloth as:

sudo gem install BlueCloth

(sudo is required for OS X.)

Written by totalrecall

February 28, 2007 at 7:05 pm

Posted in ecto, Mac OS X, ruby