<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: language code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 23 Jul 2008 21:44:37 GMT</pubDate>
    <description>DZone Snippets: language code</description>
    <item>
      <title>Ruby word count</title>
      <link>http://snippets.dzone.com/posts/show/5112</link>
      <description>&lt;code&gt;&lt;br /&gt;module StringExtensions&lt;br /&gt;  def words&lt;br /&gt;    s = self.dup&lt;br /&gt;    s.gsub!(/\w+/, 'X')&lt;br /&gt;    s.gsub!(/\W+/, '')&lt;br /&gt;    s.length&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Feb 2008 19:29:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5112</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Fast stop word detection in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/4236</link>
      <description>Requires &lt;a href="http://snippets.dzone.com/posts/show/4235"&gt;BloominSimple&lt;/a&gt; (a pure Ruby Bloom filter class).&lt;br /&gt;&lt;br /&gt;List of stop words obtained from &lt;a href="http://www.dcs.gla.ac.uk/idom/ir_resources/linguistic_utils/stop_words"&gt;http://www.dcs.gla.ac.uk/idom/ir_resources/linguistic_utils/stop_words&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;# Detect stop words QUICKLY&lt;br /&gt;# Uses a bloom filter instead of searching literally through a list of stopwords&lt;br /&gt;# for &gt; 3x speed increase&lt;br /&gt;# &lt;br /&gt;#    using bloom filter: 2.580000   0.030000   2.610000 (  2.698829)&lt;br /&gt;#  using literal search: 7.850000   0.120000   7.970000 (  8.181684)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;require 'bloominsimple'&lt;br /&gt;require 'digest/sha1'&lt;br /&gt;require 'pp'&lt;br /&gt;&lt;br /&gt;# Create a simple bloom filter that uses a SHA1 hash (more effective than BloominSimple's default hashing)&lt;br /&gt;b = BloominSimple.new(50000) do |word|&lt;br /&gt;  Digest::SHA1.digest(word.downcase.strip).unpack("VVV")&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# Add stopwords to the bloom filter!&lt;br /&gt;stopwords = []&lt;br /&gt;File.open('stopwords').each { |a| b.add(a); stopwords &lt;&lt; a.downcase.strip }&lt;br /&gt;&lt;br /&gt;# Read in a whole dictionary of regular words&lt;br /&gt;words = File.open('/usr/share/dict/words').read.split.collect{|a| a.downcase.strip }&lt;br /&gt;&lt;br /&gt;# Define two ways to detect stopwords for comparison..&lt;br /&gt;using_filter = lambda { |word| b.includes?(word) }&lt;br /&gt;using_array = lambda { |word| stopwords.include?(word.downcase.strip) }&lt;br /&gt;techniques = [using_filter, using_array]&lt;br /&gt;&lt;br /&gt;# Run stopword comparisons with both techniques&lt;br /&gt;t = techniques.collect { |l| words.collect { |a| l[a] } }&lt;br /&gt;&lt;br /&gt;# See how effective the bloom filter has been compared to the literal search&lt;br /&gt;if t[0] == t[1]&lt;br /&gt;  puts "GOOD"&lt;br /&gt;else&lt;br /&gt;  words.zip(t[0],t[1]).each do |x|&lt;br /&gt;    puts x.first if x[1] != x[2]&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# Now do speed benchmarks..&lt;br /&gt;techniques.each { |l| puts Benchmark.measure { words.each { |a| l[a] } } }&lt;/code&gt;</description>
      <pubDate>Mon, 02 Jul 2007 03:10:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4236</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>genetic algorithm in J</title>
      <link>http://snippets.dzone.com/posts/show/2834</link>
      <description>&lt;code&gt;&lt;br /&gt;-------------  Beginning of class  pga.ijs   -------------------&lt;br /&gt;coclass'pga'&lt;br /&gt;create=:3 : 0&lt;br /&gt;genes=: ? 4 $ 100  NB. 4 random integers 0-99&lt;br /&gt;)&lt;br /&gt;getgenes =: 3 : 'genes'&lt;br /&gt;setgenes =: 3 : 'genes=:y.'&lt;br /&gt;matewith=: 3 : 0&lt;br /&gt;other=. y.&lt;br /&gt;mine=. ((#genes) % 2) ? (#genes) NB. crossover&lt;br /&gt;childgene=. getgenes__other '' NB. copy others intially&lt;br /&gt;child=. conew 'pga'&lt;br /&gt;setgenes__child ((mine { genes) (mine }) childgene)&lt;br /&gt;child&lt;br /&gt;)&lt;br /&gt;perform =: 3 : 0 NB. dummy problem&lt;br /&gt;+/ genes&lt;br /&gt;)&lt;br /&gt;destroy=:codestroy&lt;br /&gt;-------------  End of of class  pga.ijs   ----------------------&lt;br /&gt;-------------  beginning of script ga.ijs ----------------------&lt;br /&gt;NB. genetic algorithm &lt;br /&gt;NB. needs pga class&lt;br /&gt;NB. define a dummy target to measure fitness against&lt;br /&gt;targetvalue =:  500  &lt;br /&gt;fitness=: 3 : 0&lt;br /&gt;object=. y.&lt;br /&gt;1000 * %(targetvalue - perform__object '')&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;load jpath '~user\classes\pga.ijs'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;top =: 4 : '(i.y.) { \: (fitness each x.)'  NB. pop top 10 returns the 10 fittest&lt;br /&gt;&lt;br /&gt;pair=: 3 : 0  NB. pick two random ga objects, mate them, and return the child&lt;br /&gt;pop=. y.&lt;br /&gt;mom=. &gt; (?#pop) { pop NB. must unbox!&lt;br /&gt;dad=. &gt; (?#pop) { pop NB.  # is length of boxed list&lt;br /&gt;matewith__mom dad&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;NB.  pop evolve generations returns the fittest ga after &lt;br /&gt;NB. sifting the top 25 ga's&lt;br /&gt;evolve=: 4 : 0&lt;br /&gt;pop=. x.&lt;br /&gt;n=. y.&lt;br /&gt;for_k. i.n do.&lt;br /&gt;kpop=.  3 : 'pop' NB. not sure if necessary to do here&lt;br /&gt;newgen=.  (pair@kpop) each i.100  NB. create 100 children&lt;br /&gt;best=.  (newgen top 25) { newgen NB. find the indices of the best, then select the corresponding objects&lt;br /&gt;pop=. best,best,best,best  NB. not really necessary?&lt;br /&gt;end.&lt;br /&gt;&gt;0{best  NB. return best&lt;br /&gt;)&lt;br /&gt;NB. usage  &lt;br /&gt;load jpath '~user\ga.ijs'&lt;br /&gt;average =: +/%#&lt;br /&gt;pop=: conew&amp;'pga' each i.100   NB. create 100 boxed ga objects&lt;br /&gt;fitness each pop  NB. should show a boxed list of fitness values&lt;br /&gt;average ; fitness each pop  NB. shows average fitness&lt;br /&gt;&lt;br /&gt;fred=: pop evolve 100&lt;br /&gt;fitness fred&lt;br /&gt;uberfred=: pop evolve 1000&lt;br /&gt;&lt;br /&gt;NB. the fitness values increase pretty slowly which is disappointing&lt;br /&gt;NB. probably needs some mutation :)&lt;br /&gt;-------------    end of script ga.ijs     ----------------------&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 15 Oct 2006 17:33:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2834</guid>
      <author>cratylus (crat)</author>
    </item>
    <item>
      <title>ruby language features</title>
      <link>http://snippets.dzone.com/posts/show/2233</link>
      <description>Unsorted list of features, howto's, suggar and evils of ruby (on rails)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# THIS FILE CONTAINS INTERESTING SNIPPETS OF RUBY/RAILS&lt;br /&gt;# in order to accelerate learning and find forgotten things&lt;br /&gt;#  &lt;br /&gt;#  Key shortcuts!&lt;br /&gt;#  ctrl+shift+v  controller/view!&lt;br /&gt;#  ctrl+k  find next word&lt;br /&gt;#  ctrl+m maximize editor&lt;br /&gt;#  &lt;br /&gt;# &lt;br /&gt;# &lt;br /&gt;#   &lt;br /&gt;BAD&lt;br /&gt;-----------------------&lt;br /&gt;model files do not contain the classes field information &lt;br /&gt;instead this is stored in different 'migration' files&lt;br /&gt;create_table "periods" do |t|&lt;br /&gt;    t.column "target_id", :integer&lt;br /&gt;    t.column "target_type", :string&lt;br /&gt;    t.column "start_at", :datetime&lt;br /&gt;    t.column "end_at", :datetime&lt;br /&gt;    t.column "wholeday", :boolean&lt;br /&gt;    t.column "wholeweek", :boolean&lt;br /&gt;    t.column "allweeks", :boolean&lt;br /&gt;  end&lt;br /&gt; NO inbuild multi dimensional arrays&lt;br /&gt;DANGER!!!!!&lt;br /&gt;and is not &amp;&amp; !!!!!!!!!!!!!!!!!!!!!!!!&lt;br /&gt;return x==7 and y==8  =&gt; void value expression!!!&lt;br /&gt;return x==7 &amp;&amp; y==8  !!!&lt;br /&gt;nr==0 (evaluates string.nil? !!!!!!!  "0"==0 -&gt; false!!!!)&lt;br /&gt;nr.to_i==0 !!&lt;br /&gt;&lt;br /&gt;#ANNOYANCES:&lt;br /&gt;+ operator for string is really baad :&lt;br /&gt;cannot convert nil into String !!! &lt;br /&gt;puts "teacher "+ @lesson.teacher&lt;br /&gt; "last saved : "+ DateTime.now.to_s  #to_s !!! neccessary!!!!!!! (and ugly)&lt;br /&gt;"nr"+rand(10).to_s#!!!&lt;br /&gt;&lt;br /&gt;Language buggy: (see http://public.transcraft.co.uk/blog/index.html)&lt;br /&gt;ActionController::RoutingError (Recognition failed for "/images/btnbg.gif"):&lt;br /&gt;&lt;br /&gt;helpers are only for views!! (ApplicationController is what you need)&lt;br /&gt;&lt;br /&gt;@links = Link.find_by_sql [&lt;br /&gt;"SELECT * from links where link like '"+ @a +"%' order by id asc"]&lt;br /&gt;  #endwith startwith&lt;br /&gt;s = "Hello, world"&lt;br /&gt;/^Hello/.match( s ) 	&gt;&gt; true&lt;br /&gt;/world$/.match( s ) 		&gt;&gt; true&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;&lt;!--bad philosopy : evaluation inside html comments?&lt;br /&gt;&lt;%#= datetime_select 'lesson', 'end_at'  %&gt;&lt;/p&gt;--&gt;&lt;br /&gt;  &lt;br /&gt;  -------------------------------------&lt;br /&gt;Good&lt;br /&gt;********************&lt;br /&gt;&lt;br /&gt;class.byname:&lt;br /&gt;&lt;br /&gt;  alle= eval(type+".find(:all)")&lt;br /&gt;  Object.const_get("Array")&lt;br /&gt;&lt;br /&gt;# default values&lt;br /&gt;def initialize(definitions=[], word = nil)       &lt;br /&gt;      @definitions = definitions&lt;br /&gt;      @word = word&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;rake db_schema_dump !!! instead of writing the migration files yourself&lt;br /&gt;&lt;br /&gt;rake --help&lt;br /&gt;rake migrate VERSION=n  #runs from 0 to n !!!!!!!!!!!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Customer.find_all [ "company = ?", company ]&lt;br /&gt;und wenn man eine LIKE '%xx%' Abfrage erstellen m&#246;chte:&lt;br /&gt;Customer.find_all [ " company LIKE ? ", '%#{company}%' ]&lt;br /&gt;&lt;br /&gt;string arrays:&lt;br /&gt;x= %w(Montag Dienstag) is short for &lt;br /&gt;y= ["Montag" ,"Dienstag"]&lt;br /&gt;&lt;br /&gt;&lt;%= sortable_element('listOrTableId' , :url =&gt; { :action =&gt; 'move' }) #, :update =&gt; 'test-id',:tag =&gt; 'tr',  :complete =&gt; visual_effect(:highlight, q.id))%&gt;&lt;br /&gt;&lt;br /&gt;&lt;%= observe_field(:search,&lt;br /&gt;	:frequency =&gt; 0.5,&lt;br /&gt;	:update =&gt; :results,&lt;br /&gt;	:url =&gt; { :action =&gt; :search }, &lt;br /&gt;	:loading =&gt; "Element.show('indicator_gif_id')",&lt;br /&gt;	:complete =&gt; "Element.hide('indicator_gif_id')") &lt;br /&gt;	%&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// HOW TOs  (mixed with 'good')&lt;br /&gt;&lt;br /&gt;global functions !&lt;br /&gt;put them in application.rb (ApplicationController)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Regular expressions&lt;br /&gt;#substitute patterns (m=LineBreaks u=Unicode i=IgnoreCase)&lt;br /&gt;a=a.gsub(/&lt;img.*?&gt;/mui, "")  # yeah right nice naming, suckers! &lt;br /&gt;&lt;br /&gt;send_file or send http response data&lt;br /&gt;  send_data @person.picture, :filename =&gt; @person.filename, :type =&gt; "image/jpeg", :disposition =&gt; "inline"&lt;br /&gt;&lt;br /&gt;require 'net/ftp'&lt;br /&gt; ftp = Net::FTP.new('ftp.netlab.co.jp') &lt;br /&gt; ftp.login files = ftp.chdir('pub/lang/ruby/contrib')&lt;br /&gt;  files = ftp.list('n*') &lt;br /&gt;  ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)&lt;br /&gt;   ftp.close&lt;br /&gt;&lt;br /&gt;#reflection : &lt;br /&gt;list.class.reflect_on_all_associations&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;regex&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;br /&gt;// greedy !!!!&lt;br /&gt;puts "a[bcb]d[bebb]rerberb]w[bsdaeb]ega".scan(/\[b(.*)b/).inspect&lt;br /&gt;=&gt;cb]d[bebb]rerberb]w[bsdae&lt;br /&gt;&lt;br /&gt;// .*? not greedy ++&lt;br /&gt;puts "a[bcb]d[bebb]rerberb]w[bsdaeb]egab".scan(/\[b(.*?)b/).inspect&lt;br /&gt;=&gt; [["c"], ["e"], ["sdae"]]&lt;br /&gt;&lt;br /&gt;#debug over ssh:&lt;br /&gt;#ruby breakpointer [options] [server uri]&lt;br /&gt;#ruby script/generate scaffold x // model + view!&lt;br /&gt;#http://www.rubycentral.com/book/tut_modules.html modules&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  require 'net/http'&lt;br /&gt;    require 'uri'&lt;br /&gt;    img='http://www.macdesktops.com/?res=TRUE&amp;category=35'&lt;br /&gt;      html=Net::HTTP.get URI.parse(img)&lt;br /&gt;&lt;br /&gt;#switch cases&lt;br /&gt; def search&lt;br /&gt;    @results = Search.find(params[:query])&lt;br /&gt;    case @results&lt;br /&gt;      when 0 then render :action=&gt; "no_results"&lt;br /&gt;      when 1 then render :action=&gt; "show"&lt;br /&gt;      when 2..10 then render :action=&gt; "show_many"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;module Action&lt;br /&gt;  VERY_BAD = 0&lt;br /&gt;  BAD      = 1&lt;br /&gt;  def Action.sin(badness)&lt;br /&gt;    # ...&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;require "trig"&lt;br /&gt;require "action"&lt;br /&gt;##########&lt;br /&gt;MIXINS&lt;br /&gt;module Debug&lt;br /&gt;  def whoAmI?&lt;br /&gt;    "#{self.type.name} (\##{self.id}): #{self.to_s}"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;class Phonograph&lt;br /&gt;  include Debug&lt;br /&gt;  # ...&lt;br /&gt;end&lt;br /&gt;class EightTrack&lt;br /&gt;  include Debug&lt;br /&gt;  # ...&lt;br /&gt;end&lt;br /&gt;ph = Phonograph.new("West End Blues")&lt;br /&gt;et = EightTrack.new("Surrealistic Pillow")&lt;br /&gt;#ph.whoAmI? 	&#187; 	"Phonograph (#537766170): West End Blues"&lt;br /&gt;#et.whoAmI? 	&#187; 	"EightTrack (#537765860): Surrealistic Pillow"&lt;br /&gt;##########################33&lt;br /&gt;time=5.minutes + 30.seconds ## cool !!!!!!&lt;br /&gt;&lt;br /&gt;5.times do |i|&lt;br /&gt;   File.open("temp.rb","w") { |f|&lt;br /&gt;     f.puts "module Temp\ndef Temp.var() #{i}; end\nend"&lt;br /&gt;   }&lt;br /&gt;   load "temp.rb"&lt;br /&gt;   puts Temp.var&lt;br /&gt; end&lt;br /&gt; ################&lt;br /&gt;print "Enter your name: "&lt;br /&gt;name = gets&lt;br /&gt;#################&lt;br /&gt;&lt;br /&gt;Argumentlisten variabler L&#228;nge&lt;br /&gt;Was aber, wenn Sie eine variable Anzahl von Argumenten &#252;bergeben wollen oder mehrere Argumente mit einem einzigen Parameter auffangen wollen? Wenn Sie einen Stern vor den Namen des Parameters nach den ``normalen'' Parametern setzen, wird genau das gemacht.&lt;br /&gt;def varargs(arg1, *rest)&lt;br /&gt;  "Got #{arg1} and #{rest.join(', ')}"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;y = Trig.sin(Trig::PI/4)&lt;br /&gt;wrongdoing = Action.sin(Action::VERY_BAD)&lt;br /&gt;# setup:&lt;br /&gt;# rails &lt;appname&gt;&lt;br /&gt;# ruby script\generate scaffold survey #!!  does the following too:&lt;br /&gt;# ruby script\generate controller survey&lt;br /&gt;# ruby script\generate model survey&lt;br /&gt;#backward if&lt;br /&gt;#def isanum=true&lt;br /&gt;puts "It's not a number" if isanum.nil?&lt;br /&gt;&lt;br /&gt;#$! variable!!&lt;br /&gt; rescue ScriptError, StandardError&lt;br /&gt;    printf "ERR: %s\n", $! || 'exception raised'&lt;br /&gt;#eval&lt;br /&gt;eval(line).inspect&lt;br /&gt;&lt;br /&gt;#regexp matching   &amp; no brackets&lt;br /&gt;if a =~ /^[-+]?\d+$/;&lt;br /&gt;	puts "It's a number that may indicate positive or negative"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Does anyone know how to get an ID back, instead of a String?&lt;br /&gt;@doctor = Doctor.find_by_name(params[:doctor][:name])&lt;br /&gt;params[:parent][:doctor] = @doctor&lt;br /&gt;&lt;br /&gt;#what is that?   yml intralanguage :(&lt;br /&gt;#  database: verwurzelt_de_development&lt;br /&gt;#  &lt;&lt;: *login&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Simplemost file IO:&lt;br /&gt;IO.foreach("testfile") { |line| puts line }&lt;br /&gt;&lt;br /&gt;arr = IO.readlines("testfile")&lt;br /&gt;&lt;br /&gt;#Simple socket&lt;br /&gt;require 'socket'&lt;br /&gt;client = TCPSocket.open('localhost', 'finger')&lt;br /&gt;client.send("oracle\n", 0)    # 0 means standard packet&lt;br /&gt;puts client.readlines&lt;br /&gt;client.close&lt;br /&gt;&lt;br /&gt;#HTTP&lt;br /&gt;require 'net/http'&lt;br /&gt;h = Net::HTTP.new('www.pragmaticprogrammer.com', 80)&lt;br /&gt;resp, data = h.get('/index.html', nil)&lt;br /&gt;if resp.message == "OK"&lt;br /&gt;  data.scan(/&lt;img src="(.*?)"/) { |x| puts x }&lt;br /&gt;end #get images!&lt;br /&gt;&lt;br /&gt;#error handling:&lt;br /&gt;  f = File.open("testfile")&lt;br /&gt;begin&lt;br /&gt;  f.each_line {|line| puts "Got #{line.dump}" }&lt;br /&gt;  # .. process&lt;br /&gt;  raise ArgumentError, "Name too big", caller&lt;br /&gt;rescue ArgumentError&lt;br /&gt;#rescue &lt;br /&gt;  # .. handle error&lt;br /&gt;else&lt;br /&gt;  puts "Congratulations-- no errors!"&lt;br /&gt;ensure&lt;br /&gt;  f.close unless f.nil?&lt;br /&gt;end&lt;br /&gt;#############&lt;br /&gt; # SICK : two mechanisms!!!&lt;br /&gt; def promptAndGet(prompt)&lt;br /&gt;  print prompt&lt;br /&gt;  res = readline.chomp&lt;br /&gt;  throw :quitRequested if res == "!"&lt;br /&gt;  return res&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;catch :quitRequested do&lt;br /&gt;  name = promptAndGet("Name: ")&lt;br /&gt;  age  = promptAndGet("Age:  ")&lt;br /&gt;  sex  = promptAndGet("Sex:  ")&lt;br /&gt;  # ..&lt;br /&gt;  # process information&lt;br /&gt;end&lt;br /&gt;#############&lt;br /&gt;  &lt;br /&gt;require 'breakpoint'&lt;br /&gt;Thread.new do&lt;br /&gt;loop do&lt;br /&gt;begin&lt;br /&gt;breakpoint&lt;br /&gt;rescue Exception&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript" language="javascript" charset="utf-8"&gt;&lt;br /&gt;// &lt;![CDATA[&lt;br /&gt;  Sortable.create('sortlist',{ghosting:false,constraint:false,hoverclass:'over',&lt;br /&gt;    //onUpdate:function(sortable){alert(Sortable.serialize(sortable))},&lt;br /&gt;    onChange:function(element){&lt;br /&gt;	var	data=    Sortable.serialize(element.parentNode);&lt;br /&gt;	var url="&lt;%=url_for :controller=&gt;'question',:action=&gt;'move'%&gt;";&lt;br /&gt;	new Ajax.Request(url,{parameters:data});&lt;br /&gt;    }&lt;br /&gt;  });&lt;br /&gt;// ]]&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 29 Jun 2006 01:27:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2233</guid>
      <author>pannous ()</author>
    </item>
    <item>
      <title>Inputing non-ascii characters</title>
      <link>http://snippets.dzone.com/posts/show/631</link>
      <description>My mobile phone (6600) doesn't have a Thai input method.&lt;br /&gt;(You can buy a special software to do it)&lt;br /&gt;After a lot of my thought experiments, I got an easy&lt;br /&gt;example from my friend on this. You do a 2-level popup menu&lt;br /&gt;to let people choose from the character table.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from appuifw import *&lt;br /&gt;&lt;br /&gt;def thai_input():&lt;br /&gt;    first_list = ['  '.join(thai_char[i:i+11]) for i in range(0,77,11)]&lt;br /&gt;    y = popup_menu(first_list, u'select Thai char')&lt;br /&gt;    if y is not None:&lt;br /&gt;        x = popup_menu(thai_char[11*y:11*(y+1)], u'select Thai char')&lt;br /&gt;        if x is not None:&lt;br /&gt;            t.add(thai_char[11*y + x])&lt;br /&gt;&lt;br /&gt;thai_char = [unichr(0x0e01+i) for i in range(77)]   # 77 thai characters&lt;br /&gt;&lt;br /&gt;app.body = t = Text()&lt;br /&gt;app.menu = [(u'thai', thai_input), (u'clear screen', t.clear)] &lt;br /&gt;&lt;br /&gt;# wait for user to exit program&lt;br /&gt;import e32      &lt;br /&gt;lock = e32.Ao_lock() &lt;br /&gt;app.exit_key_handler=lock.signal&lt;br /&gt;lock.wait()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For other language, you can change the unicode offset (0x0e01)&lt;br /&gt;and number of characters (77) to that of your language.&lt;br /&gt;One requirement for this method is that the phone must be&lt;br /&gt;able to display font in your language already. &lt;br /&gt;(I have previously install Thai font on my 6600)&lt;br /&gt;An alternative method to implement this will be manually drawing&lt;br /&gt;your text (combile character from image font file).&lt;br /&gt;I may do that some day.</description>
      <pubDate>Sun, 04 Sep 2005 21:48:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/631</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
