PullMonkey Blog


17 Nov

Formgen 0.3.0 and some generated examples


Formgen generates views in erb and haml based on these keywords: has_many, belongs_to, accepts_nested_attributes_for, and has_attached_file. It follows best practice and standard patterns so you don't have to. Here is example of its usage:

Doing this

rails generate skizmo:form Foo

Generates this

app/helpers/foo_setup_helper.rb

app/views/foos/new.html.erb

app/views/foos/edit.html.erb

app/views/foos/_form.html.erb

app/views/foos/_bar_fields.html.erb

app/views/foos/_baz_fields.html.erb


That's it:

Ok, so I say that, but there are a few things to note. First, this probably only works with Rails 3, given some of the calls I make for figuring things out. Next, you'll want to yield :head, somewhere in your layout so that the content_for :head that loads the add and remove jQuery will be useful. Finally, you should note that the nested attributes are only processed from the first level, but that will soon change. Anyway, enjoy it and if you have any problems, just let me know.


Comments Off on Formgen 0.3.0 and some generated examples Filed under: Uncategorized
16 Nov

Form Gen – ruby on rails gem


I've always dreaded doing the view code for nested attributes, setting up the helpers, the javascript, partials etc. Just so tedious, so I thought, I'd try my hand at a form generator. This generator takes a class and then processes all the nested attributes of that class's has_many's and belongs_to's to generate the typical pattern of form partial and field partials you find here.

Yah I did ruby syntax-highlighting ... so not the best for something like that, but eh ... it'll do.

The formgen gem is a 0.1.0 starting point, but has worked for all the things I've needed. If you're feeling brave give it a shot:

# In your Gemfile -
gem 'formgen'
# then from your rails projects -
rails g skizmo:form SomeClass

That outta do it.


Comments Off on Form Gen – ruby on rails gem Filed under: Uncategorized
15 Nov

Azilink is working again !


If the apk is not available for download yet, you can build it yourself with the fix from here.
Step 1 - Grab the source from svn -

svn checkout http://azilink.googlecode.com/svn/trunk/ azilink-read-only

Step 2 - Update the UdpDriver.java per this azilink issue.

Step 3 - Build and install the apk

# this will give you a build.xml file
android update project --target 2 --path /path/to/your/azilinkdownload/
# after plugging in your device and from your azilink project directory
ant debug install

Step 4 - Install Open VPN

sudo apt-get install openvpn

Step 5 - Grab the azilnk.ovpn file from the downloads section.
Place somewhere you won't lose it.

Step 6 - Copy this resolv.azilink file to the same place as the azilink.ovpn

Step 7 - Copy this azilink script to somewhere you can get to it

Step 8 - Start azilink on your phone.

Step 9 - Run the script from step 7.

That's it.


13 Nov

Hello Android – Pindah (with Mirah) Application


Did you install the Android SDK / JDK, etc?  If not, start here - http://developer.android.com/sdk/index.html.
If you're running 64-bit like me, make sure to install the ia32-libs, since the SDK is 32-bit.

This is completely based on the Hello Android tutorial - I didn't really do a whole lot, but the hope is that this will help get some more ruby devs into android development with a simple how-to.

Step 1 - Setup RVM with jruby

Note: RVM is awesome, if you don't use it or don't know about it - read more here.

rvm install jruby
cd /path/to/your/android/pindah/mirah/project/dir/
# using your .rvmrc will trigger `rvm use jruby` when you cd into your project dir.
echo "rvm use jruby" > .rvmrc
# this will make sure your .rvmrc is working, you should then be able 
# to use rvm info and see jruby
cd .

Step 2 - Install the mirah and pindah gems

# too easy
gem install mirah pindah

Step 3 - Create your first pindah app

pindah create com.example.android.hello_world
cd hello_world

Step 4 - Create your activity - HelloAndroid.mirah

# from your project dir and inside your pindah app dir 
<editor> src/com/example/android/hello_world/HelloWorld.mirah

This is the code I used:

Step 5 - Setup your AndroidManifest.xml file

This is where you define your app, version, name, etc, but more importantly for this example - what activity will handle your main intent.
Mine looks like this:

Step 6 - Install to your device

# make sure a device is recognized  ... 
# and make sure adb is in your path (platform-tools in the SDK)
adb devices
rake install


Comments Off on Hello Android – Pindah (with Mirah) Application Filed under: Android, development, ruby, tutorials Tags: , , , , ,
10 Nov

Playing with Mirah


Mirah (formally duby) is pretty freaking cool.   Plans are to scrap java and use mirah for future android development, we'll see.  Here's a rough example of some pretty basic mirah.

To get started, you'll need jruby and the mirah gem:

rvm install jruby
rvm use jruby (or put in your .rvmrc)
gem install mirah

Then create an example:

puts "hello world!!"
500.times do |x|
  puts x
end

Time in ruby:

time ruby test.mirah

...
=> .457s

Compile to Java and time:

mirahc test.mirah
time java Test

....
=> .081s

Less than 1/5 the time and it compiles to Java ... neat 🙂

mirahc -j test.mirah

// Generated from test.mirah
public class Test extends java.lang.Object {
  public static void main(java.lang.String[] argv) {
    int __xform_tmp_1 = 0;
    int __xform_tmp_2 = 0;
    int x = 0;
    java.io.PrintStream temp$1 = java.lang.System.out;
    temp$1.println("hello world");
    __xform_tmp_1 = 0;
    __xform_tmp_2 = 500;
    label2:
    while ((__xform_tmp_1 < __xform_tmp_2)) {
      x = __xform_tmp_1;
      label3:
       {
        java.io.PrintStream temp$4 = java.lang.System.out;
        temp$4.println(x);
      }
      __xform_tmp_1 = (__xform_tmp_1 + 1);
    }
  }
}

09 Nov

Using ruby to consolidate a list of numbers by shortening with hyphens


Check it out -


Comments Off on Using ruby to consolidate a list of numbers by shortening with hyphens Filed under: development, ruby Tags: , ,