Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Twitter and Jaiku from the command line

The following instructions make it easy to post to Twitter and Jaiku from the command line. The instructions were copied from the article "Ubuntu Unleashed: Howto Twitter From the Command Line in Ubuntu!" [ubuntu-unleashed.com] and modified to post via Rorbuilder's ProjectX API.

sudo apt-get install curl

sudo gedit /usr/bin/jaitwit

Now Paste this in gEdit and simply replace "YourUsername" with your username and "YourPassword" with your twitter passwd, then replace the Jaiku variables (YourUsername, YourPassword, YourCity, YourAccessKey) and ctrl-s to save, then alt-F4 to exit!
curl http://rorbuilder.info/api/projectx.cgi?xml_project=%3Cproject%20name=%22micro_blog%22%3E%3Cmethods%3E%3Cmethod%20name=%22post2jaiku%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22location%22%20val=%22YourCity%22/%3E%3Cparam%20var=%22apikey%22%20val=%22YourAccessKey%22/%3E%3C/params%3E%3C/method%3E%3Cmethod%20name=%22post2twitter%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22password%22%20val=%22YourPassword%22/%3E%3C/params%3E%3C/method%3E%3C/methods%3E%3C/project%3E -o /dev/null
echo Message Sent!

Then chmod for exec privileges:
chmod +x /usr/bin/jaitwit

Then from the CLI type jaitwit followed by your message.
jaitwit "message here without the quotes"

A QT 'Hello World' application

- getting started - (Using Ubuntu Linux 7.10)
1) Installed Qt bindings for Ruby

- Running the application
1) From the command line I typed ruby helloworld_qt.rb

#file: helloworld_qt.rb

require 'Qt'

    a = Qt::Application.new( ARGV )

    hello = Qt::PushButton.new( "Hello world!", nil )
    hello.resize( 100, 30 )
 
    Qt::Object::connect( hello, SIGNAL('clicked()'), a, SLOT('quit()') )
 
    a.setMainWidget( hello )
    hello.show()
 
    a.exec()

Source code copied from KDE Tutorial - p1 [kde.org]

A Glade 'Hello World' application

- getting started - (Using Ubuntu Linux 7.10)
1) Installed glade-3,libglade2-ruby
2) Executed glade-3

- Within glade-3 -
1) Selected from the glade-3 top menu View -> Palette appearance -> Text beside icons
2) Created a window (Toplevels)
3) Created a button on the window (Control and Display)
3) With button selected, from the properties panel I selected the Signals tab and chose 'clicked', then for the Handler -> on_button1_clicked and pressed enter.
4) With window select, from the properties panel I select the Signals tab and chose GtkWidget->delete-event, then for the Handler I typed on_quit and pressed enter.

- Generating and editing the code

-- From the command line -
1) Typed ruby-glade-create-template helloworld3.glade > helloworld3.rb

-- From the file helloworld3.rb - (see helloworld3.rb and how it relates to helloworld3.glade)
1) Implemented the initialise window routine
2) Implemented the button event handler

- Running the application
1) From the command line I typed ruby helloworld3.rb
2) stretched the window to a comfortable dimension.
3) clicked the button and observed the Window title change to 'Hello World!'

file: helloworld3.glade
#!/usr/bin/env ruby
#
# This file is generated by ruby-glade-create-template 1.1.4.
#
require 'libglade2'

class Helloworld3Glade
  include GetText

  attr :glade
  
  def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
    bindtextdomain(domain, localedir, nil, "UTF-8")
    @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
    @window1 = @glade.get_widget("window1") # hand coded
    @window1.show # hand coded      
  end
  
  def on_button1_clicked(widget)
    #puts "on_button1_clicked() is not implemented yet." # removed this code by hand
    @window1.title = 'Hello World!' # hand coded  
  end
  def on_quit(widget, arg0)
    #puts "on_quit() is not implemented yet." # removed this code by hand
    Gtk.main_quit # hand coded
  end
end

# Main program
if __FILE__ == $0
  # Set values as your own application. 
  PROG_PATH = "helloworld3.glade"
  PROG_NAME = "YOUR_APPLICATION_NAME"
  Helloworld3Glade.new(PROG_PATH, nil, PROG_NAME)
  Gtk.main
end

file: helloworld3.glade
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Tue Mar 18 17:39:53 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <signal name="delete_event" handler="on_quit"/>
    <child>
      <widget class="GtkButton" id="button1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <property name="label" translatable="yes">button</property>
        <property name="response_id">0</property>
        <signal name="clicked" handler="on_button1_clicked"/>
      </widget>
    </child>
  </widget>
</glade-interface>

Using Espeak

Espeak is a Text-to-speech program which I have used on Ubuntu. A sample of the audio can be found from my twittergram [twittergram.com]. Note: I made a few spelling mistakes in the audio, listen and tell me if you can hear them.

espeak -f hello_jr -s 120

Wget's switch to preserve the filename

Download a file and preserve the filename. Without the switch -O the next time the file is downloaded the new filename would be projxmlbase.rb.1

wget -O projxmlbase.rb http://xml.mysqueak.info/p/projxmlbase.rb
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS