<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: text code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 11 Oct 2008 21:28:52 GMT</pubDate>
    <description>DZone Snippets: text code</description>
    <item>
      <title>Adding a combo box to a Ruby Maemo application</title>
      <link>http://snippets.dzone.com/posts/show/6215</link>
      <description>Here is a script to run a Ruby Maemo application which has a combo box.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /usr/bin/env ruby&lt;br /&gt;#file: combo.rb&lt;br /&gt;&lt;br /&gt;#require 'gtk'&lt;br /&gt;require 'hildon'&lt;br /&gt;&lt;br /&gt;program = Hildon::Program.instance&lt;br /&gt;&lt;br /&gt;#window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)&lt;br /&gt;window = program.add_window Hildon::Window.new&lt;br /&gt;&lt;br /&gt;combo = Gtk::Combo.new&lt;br /&gt;combo.set_popdown_strings(['http://www.netlab.co.jp/ruby/',&lt;br /&gt;			    'http://ruby.freak.ne.jp/'])&lt;br /&gt;combo.entry.set_text ''&lt;br /&gt;window.add(combo)&lt;br /&gt;combo.show&lt;br /&gt;window.show&lt;br /&gt;Gtk.main&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can see from the &lt;a href="http://twitxr.com/image/107122/"&gt;output on the N800&lt;/a&gt; [twitxr.com] as I selected an item from the combo box'.&lt;br /&gt;&lt;br /&gt;Resources:&lt;br /&gt; - &lt;a href="http://snippets.dzone.com/posts/show/6214"&gt;Adding a text entry box in a Ruby Maemo application&lt;/a&gt; [dzone.com]&lt;br /&gt; - &lt;a href="http://ruby-gnome.sourceforge.net/programming/entry.html"&gt;&#12456;&#12531;&#12488;&#12522;&#12454;&#12451;&#12472;&#12455;&#12483;&#12488;&#12392;&#12467;&#12531;&#12508;&#12454;&#12451;&#12472;&#12455;&#12483;&#12488; - Ruby/Gtk Programming&lt;/a&gt; [sourceforge.net]&lt;br /&gt; - &lt;a href="http://ruby-gnome.sourceforge.net/programming/hello.html"&gt;Hello World in Ruby/GTK&lt;/a&gt; [sourceforge.net]</description>
      <pubDate>Tue, 07 Oct 2008 15:32:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6215</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Adding a text entry box in a Ruby Maemo application</title>
      <link>http://snippets.dzone.com/posts/show/6214</link>
      <description>Here is a script to run a Ruby Maemo application which has a text entry box.  There's nothing special about this code other than it uses 'hildon' instead of Gtk. &lt;br /&gt;&lt;br /&gt;The only code changes from the original Ruby GTK code was to comment out the gtk include file and the Gtk Window.new statement.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /usr/bin/env ruby&lt;br /&gt;#file: entry.rb&lt;br /&gt;&lt;br /&gt;#require 'gtk'&lt;br /&gt;require 'hildon'&lt;br /&gt;&lt;br /&gt;program = Hildon::Program.instance&lt;br /&gt;&lt;br /&gt;#window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)&lt;br /&gt;window = program.add_window Hildon::Window.new&lt;br /&gt;&lt;br /&gt;label = Gtk::Label.new('Name:')&lt;br /&gt;entry = Gtk::Entry.new&lt;br /&gt;entry.set_text('John')&lt;br /&gt;box = Gtk::HBox.new(false, 0)&lt;br /&gt;box.pack_start label, true, true, 5&lt;br /&gt;box.pack_start entry, true, true, 5&lt;br /&gt;label.show&lt;br /&gt;entry.show&lt;br /&gt;&lt;br /&gt;entry.signal_connect('activate') {|widget|&lt;br /&gt;  print "Your name is #{entry.get_text}\n"&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;window.add(box)&lt;br /&gt;box.show&lt;br /&gt;window.show&lt;br /&gt;Gtk.main&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can see from the &lt;a href="http://twitxr.com/image/107118/"&gt;output on the N800&lt;/a&gt; [twitxr.com] as I replaced the entry value 'John' with 'Jim'.&lt;br /&gt;&lt;br /&gt;Resources:&lt;br /&gt; - &lt;a href="http://ruby-gnome.sourceforge.net/programming/entry.html"&gt;&#12456;&#12531;&#12488;&#12522;&#12454;&#12451;&#12472;&#12455;&#12483;&#12488;&#12392;&#12467;&#12531;&#12508;&#12454;&#12451;&#12472;&#12455;&#12483;&#12488; - Ruby/Gtk Programming&lt;/a&gt; [sourceforge.net]&lt;br /&gt; - &lt;a href="http://ruby-gnome.sourceforge.net/programming/hello.html"&gt;Hello World in Ruby/GTK&lt;/a&gt; [sourceforge.net]</description>
      <pubDate>Tue, 07 Oct 2008 15:15:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6214</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Listen to your XMPP messages with Festival</title>
      <link>http://snippets.dzone.com/posts/show/6096</link>
      <description>Source: &lt;a href="http://linuxgazette.net/149/unnikrishnan.html"&gt;Fun with Instant Messaging and Ruby LG #149&lt;/a&gt; [linuxgazette.net]&lt;br /&gt;&lt;snip&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;require 'rubygems'  &lt;br /&gt;require 'xmpp4r-simple'  &lt;br /&gt;&lt;br /&gt;username = 'monica'&lt;br /&gt;password = 'password4monica'&lt;br /&gt;$to_username = "james"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;def talk(x)&lt;br /&gt;  system("echo '#{x}' | festival --tts")&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;puts "connecting to jabber server..."  &lt;br /&gt;jabber = Jabber::Simple.new(username+'@jamesrobertson.eu', password)  &lt;br /&gt;puts "Connected."  &lt;br /&gt;jabber.deliver($to_username+"@jamesrobertson.eu", "Hello..!")  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thread.new{&lt;br /&gt;  while true&lt;br /&gt;    jabber.deliver($to_username+"@jamesrobertson.eu", $stdin.gets)  &lt;br /&gt;    puts "-"*80  &lt;br /&gt;  end&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;while (true) do  &lt;br /&gt;  jabber.received_messages do |msg|  &lt;br /&gt;    puts "="*80  &lt;br /&gt;    $to_username = msg.from.node&lt;br /&gt;    puts  msg.from.node + ":" + msg.body&lt;br /&gt;&lt;br /&gt;    talk msg.body.gsub(/&amp;lt;/,'&lt;').gsub(/&amp;gt;/,'&gt;').gsub(/&amp;apos;/,'').gsub(/&amp;quot;/,'"').gsub(/&amp;amp;/,'&amp;')&lt;br /&gt;&lt;br /&gt;  end &lt;br /&gt;  sleep(1) &lt;br /&gt;end  &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/snip&gt;&lt;br /&gt;&lt;br /&gt;This script was tested on Ubuntu 8.04 within a VirtualBox VM containing Ubuntu 8.04, with Ruby 1.8.6, Festival, and festvox-rablpc16k.&lt;br /&gt;&lt;br /&gt;I found the script while googling for &lt;a href="http://www.google.com/search?ie=UTF8&amp;q=ruby+im+gateway"&gt;'ruby im gateway'&lt;/a&gt; [google.co.uk]</description>
      <pubDate>Fri, 19 Sep 2008 15:01:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6096</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Change Ubuntu's default text editor</title>
      <link>http://snippets.dzone.com/posts/show/6012</link>
      <description>Tired with using nano as the default text editor in Ubuntu? To change the text editor permanently to vi type the following command from the command line.&lt;br /&gt;&lt;code&gt;sudo update-alternatives --config editor&lt;/code&gt;</description>
      <pubDate>Tue, 02 Sep 2008 15:40:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6012</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Convert a PDF document to text</title>
      <link>http://snippets.dzone.com/posts/show/6010</link>
      <description>&lt;code&gt;pdftotext book.pdf &gt; book.txt&lt;/code&gt;</description>
      <pubDate>Mon, 01 Sep 2008 20:44:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6010</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Strip the line numbers from code snippets</title>
      <link>http://snippets.dzone.com/posts/show/5929</link>
      <description>Source: &lt;a href="http://saaridev.blogspot.com/2007/12/ruby-one-liner-to-strip-line-number.html"&gt;Saari Development: Ruby: One liner to strip the line number from code posted&lt;/a&gt; [blogspot.com]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby -lne 'puts $_.gsub(/^\s+?\d+\s/,"")' ali.rb &gt; ali.rb&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's a page that allows you to &lt;a href="http://rorbuilder.info/r/strip-line-numbers/index.html"&gt;strip line numbers without any script&lt;/a&gt; [rorbuilder.info] or here http://rubyurl.com/umxP .</description>
      <pubDate>Sat, 16 Aug 2008 11:49:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5929</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>use markdown with django</title>
      <link>http://snippets.dzone.com/posts/show/5912</link>
      <description>http://www.freewisdom.org/projects/python-markdown/Django&lt;br /&gt;&lt;br /&gt;Install markdown and make sure it is in your python path. &lt;br /&gt;&lt;br /&gt;http://www.freewisdom.org/projects/python-markdown/Installation&lt;br /&gt;&lt;br /&gt;Include 'django.contrib.markup' in INSTALLED_APPS in your settings.py file.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;..load&lt;br /&gt;{% load markup %}&lt;br /&gt;&lt;br /&gt;..then use&lt;br /&gt;{{ post.body|markdown }}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 13 Aug 2008 09:46:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5912</guid>
      <author>indiehead (John)</author>
    </item>
    <item>
      <title>Fill text with javascript</title>
      <link>http://snippets.dzone.com/posts/show/5809</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;/*** Temporary text filler function. Remove when deploying template. ***/&lt;br /&gt;var gibberish=["This is just some filler text", "Another some text here", "Demo content nothing to read here"]&lt;br /&gt;function filltext(words){&lt;br /&gt;for (var i=0; i&lt;words; i++)&lt;br /&gt;document.write(gibberish[Math.floor(Math.random()*3)]+" ")&lt;br /&gt;}&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;filltext(255)&lt;/script&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 Jul 2008 08:00:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5809</guid>
      <author>ciceraccio (Ciceraccio)</author>
    </item>
    <item>
      <title>Javascript count line breaks</title>
      <link>http://snippets.dzone.com/posts/show/5770</link>
      <description>Returns the number of line breaks in a string.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function lineBreakCount(str){&lt;br /&gt;	/* counts \n */&lt;br /&gt;	try {&lt;br /&gt;		return((str.match(/[^\n]*\n[^\n]*/gi).length));&lt;br /&gt;	} catch(e) {&lt;br /&gt;		return 0;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 15 Jul 2008 08:57:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5770</guid>
      <author>featurelover (Jochen Preusche)</author>
    </item>
    <item>
      <title>Converting text to SVG</title>
      <link>http://snippets.dzone.com/posts/show/5388</link>
      <description>First of all the Ruby code reads the text, splits it into an array and then saves it in XML format.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;a = "Open source is a development method for software that harnesses the power of distributed peer &lt;br /&gt;review and transparency of process. The promise of open source is better quality, higher reliability, &lt;br /&gt;more flexibility, lower cost, and an end to predatory vendor lock-in.".split(' ') &lt;br /&gt;&lt;br /&gt;doc = Document.new&lt;br /&gt;doc.add_element('text')&lt;br /&gt;oline = Element.new('line')&lt;br /&gt;&lt;br /&gt;char_count = 0&lt;br /&gt;a.each do |word|&lt;br /&gt;  &lt;br /&gt;  oword = Element.new('word')&lt;br /&gt;  oword.text = word.to_s&lt;br /&gt;  oword.add_attribute('length',char_count)&lt;br /&gt;  oline &lt;&lt; oword &lt;br /&gt;  char_count += word.length&lt;br /&gt;  &lt;br /&gt;  if char_count &gt; 50&lt;br /&gt;    doc.root &lt;&lt; oline&lt;br /&gt;    oline = Element.new('line')&lt;br /&gt;    char_count = 0&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;doc.root &lt;&lt; oline&lt;br /&gt;puts char_count&lt;br /&gt;puts doc&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's a sample of the XML created&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;text&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;Open&lt;/word&gt;&lt;word length='4'&gt;source&lt;/word&gt;&lt;word length='10'&gt;is&lt;/word&gt;&lt;br /&gt;    &lt;word length='12'&gt;a&lt;/word&gt;&lt;word length='13'&gt;development&lt;/word&gt;&lt;word length='24'&gt;method&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;for&lt;/word&gt;&lt;word length='33'&gt;software&lt;/word&gt;&lt;word length='41'&gt;that&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;harnesses&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;the&lt;/word&gt;&lt;word length='3'&gt;power&lt;/word&gt;&lt;br /&gt;    &lt;word length='8'&gt;of&lt;/word&gt;&lt;word length='10'&gt;distributed&lt;/word&gt;&lt;word length='21'&gt;peer&lt;/word&gt;&lt;br /&gt;    &lt;word length='25'&gt;review&lt;/word&gt;&lt;word length='31'&gt;and&lt;/word&gt;&lt;word length='34'&gt;transparency&lt;/word&gt;&lt;br /&gt;    &lt;word length='46'&gt;of&lt;/word&gt;&lt;word length='48'&gt;process.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;The&lt;/word&gt;&lt;br /&gt;    &lt;word length='3'&gt;promise&lt;/word&gt;&lt;word length='10'&gt;of&lt;/word&gt;&lt;word length='12'&gt;open&lt;/word&gt;&lt;br /&gt;    &lt;word length='16'&gt;source&lt;/word&gt;&lt;word length='22'&gt;is&lt;/word&gt;&lt;word length='24'&gt;better&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;quality,&lt;/word&gt;&lt;word length='38'&gt;higher&lt;/word&gt;&lt;word length='44'&gt;reliability,&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;more&lt;/word&gt;&lt;word length='4'&gt;flexibility,&lt;/word&gt;&lt;word length='16'&gt;lower&lt;/word&gt;&lt;br /&gt;    &lt;word length='21'&gt;cost,&lt;/word&gt;&lt;word length='26'&gt;and&lt;/word&gt;&lt;word length='29'&gt;an&lt;/word&gt;&lt;br /&gt;    &lt;word length='31'&gt;end&lt;/word&gt;&lt;word length='34'&gt;to&lt;/word&gt;&lt;word length='36'&gt;predatory&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;vendor&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;lock-in.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;&lt;/text&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The XML is then transformed to SVG using the following XSL file&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="text"&gt;&lt;br /&gt;    &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                  xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;      &lt;g id="sketch" class="sketch"&gt;&lt;br /&gt;        &lt;xsl:apply-templates select="line"/&gt;&lt;br /&gt;      &lt;/g&gt;&lt;br /&gt;    &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="line"&gt;&lt;br /&gt;    &lt;xsl:variable name="xfactor"&gt;12&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="yfactor"&gt;20&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="pos" select="position()"&gt;&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:apply-templates select="word"&gt;&lt;br /&gt;      &lt;xsl:with-param name="xfactor" select="$xfactor"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;      &lt;xsl:with-param name="y" select="$pos * $yfactor + 10"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;    &lt;/xsl:apply-templates&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;  &lt;xsl:template match="word"&gt;&lt;br /&gt;    &lt;xsl:param name="xfactor"/&gt;&lt;br /&gt;    &lt;xsl:param name="y"/&gt;&lt;br /&gt;    &lt;text xmlns="http://www.w3.org/2000/svg" font-size="12pt" x="{@length * $xfactor +10}" y="{$y}" id="t1"&gt;&lt;xsl:value-of select="."/&gt;&lt;/text&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The final &lt;a href="http://www.twitxr.com/image/31865/"&gt;SVG output&lt;/a&gt; [twitxr.com] shows 5 lines of text with each word as a separate SVG text element.</description>
      <pubDate>Fri, 18 Apr 2008 18:14:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5388</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
