Android: Getting GoogleVoice to work with Republic Wireless

Categories: Android
Comments: No Comments
Published on: December 1, 2011

I received my phone from Republic Wireless earlier this week.
Having two phones for the moment, I decided to set up a Google Voice account.
When I tried to test it with my RW phone I encountered issues both calling and receiving calls.
I spent some time trying to find out what’s going on.

Here’s what I found:
As far as I can tell, GoogleVoice attempts to send and receive calls via the phone’s cell signal.
When RW’s phones are on a wireless network, this doesn’t work.

RW tells me that they’re looking into a solution: RW’s Twitter Response.
Update: RW has a blog post about the state of the beta that addresses this as one of the issues: State of the Beta: Vol 1

There are lots of requests floating around for Google Voice to be reachable by wireless instead but the feature has not been implemented at this time.
There are several services that will let you do this as one of their features.

My solution:
I ended up using an app called GrooVe IP.
It’s a $5 android app you can get here: GrooVe IP.
I know it’s not free but I’ve found it to be $5 well spent.
It has several features that help clear up some bugs that might occur.
If you feel more patient, remember RW is working on this.

GrooVe IP Settings:
For GrooVe IP to work for incoming calls you need to forward calls to your Google Chat. This is in your Settings on the GoogleVoice site: GoogleVoice.
This is stated in the program description on its Android market page.

The following settings are what I have changed specifically for this phone (LG Optimus LG-LS670):
Settings -> Allow 3G/4G calling: OFF
I turned this off mostly to ensure it was using my wireless signal instead.
If you would need this on, you will be using the cell network instead of the wireless network and GoogleVoice should be able to use your phone directly without needing GrooVe IP.

Settings -> Troubleshooting -> Keep Screen On: ON
When I received GV calls over Wireless the screen would almost instantly turn off.
I needed to open the Dialpad to accept the call due to GV Call Screening being on and this caused a lot of problems.

Settings -> Troubleshooting -> Synchronize Voice: ON
This is one of the potential fixes for not having voice, particularly on outgoing calls.
Incoming calls were working fine and I could hear the other party on outgoing calls but they couldn’t hear me. This cleared that right up.

Settings -> Troubleshooting -> Partial Wave Lock: ON
This is meant to fix issues like the phone not ringing until it’s about to go to voice mail.
I do not recall turning this on so it may be on by default or I may have turned it on because it sounded good.
It does increase battery use, however.

Tests:
Cell – Incoming through normal number:
Successful. Normal system dialer answered.

Cell – Incoming through Google Voice:
Successful. Normal system dialer answered.
[Before GrooVe IP install]

Wireless – Incoming through normal number:
Successful. Normal system dialer answered.

Wireless – Incoming through GoogleVoice #:
Successful. GrooVe IP with Allow 3G/4G Data disabled, Partial Wave Lock active, and Keep Screen On active.

Cell – Outgoing through normal dialer:
Successful. Normal system dialer answered.

Cell – Outgoing through GrooVe IP:
Successful. GrooVe IP with Allow 3G/4G Data disabled, Partial Wave lock active, Keep Screen On active, and Syncronize Voice active.

Cell – Outgoing through Google Voice:
Successful. GoogleVoice option in normal Dialer.
[Before GrooVe IP install]

Hopefully I listed all of those correctly.
I’ll correct them should I find they are wrong.
The calls marked Before GrooVe IP install have not been reproduced after the install but should still work.
I will try to get around to redoing those tests and updating the post.

Ruby: Rounding floats to decimal precision for 1.8.7

Categories: Ruby
Comments: 2 Comments
Published on: September 21, 2011

Somewhere around 1.9 ruby’s round function was redone to allow for an elegant way to round decimal numbers to a given precision.

For those of us still using 1.8.7 at times, Ruby doesn’t have a really elegant way to round floats to a level of precision because .round only rounds up to the nearest whole number.

The method I prefer to achieve this goes something like this:

# 2 decimal precision
(my_float * 100).round.to_f / 100

This will shift the decimal place over two places, round it to a whole number, and shift it two places back.

To make it handle any level of precision we can convert it into this:

# variable level decimal precision
p = 2
(my_float * 10**p).round.to_f / 10**p

This uses the same idea by raising 10 to a power equal to the precision you want. Two would be 100, three would be 1000, etc.

Finally we can stop repeating ourselves and simply add this to the float class.
I don’t bother with doing this to all numbers.

class Float
    def precision(p)
        # Make sure the precision level is actually an integer and > 0
        raise ArgumentError, "#{p} is an invalid precision level. Valid ranges are integers > 0." unless p.class == Fixnum or p < 0
        # Special case for 0 precision so it returns a Fixnum and thus doesn't have a trailing .0
        return self.round if p == 0
        # Standard case
        return (self * 10**p).round.to_f / 10**p
    end
end

Do note that this doesn’t allow for negative precision like .round in 1.9.2 does.
This is because I don’t need it and rather have an error than misuse it somehow.
If you need that feature simply change the unless statement on the raise line.

There you have it, easy to use rounding in 1.8.7.

test = 10.33333
test.round(2)
=> 10.33

After I wrote this I found someone else that previously wrote almost the exact same method:
http://rubyglasses.blogspot.com/2007/09/float-precision.html
The author covers a broader version that covers more than Floats in their comments.

Ruby: Handling potential hang points with Timeout

Categories: Ruby
Tags: , ,
Comments: 2 Comments
Published on: June 21, 2011

Today I encountered a problem where a Net::HTTP post didn’t return.
When I became aware of it, it had been hanging for two hours already holding up a long running back end process.

Timeout provided a clean, simple way to handle this issue in case it reoccurs.

Some details on the issue and the usage of Timeout follow.
(more…)

PHP: Excel with ODBC

Categories: PHP
Tags: , ,
Comments: No Comments
Published on: June 7, 2011

I’ve been working on a project that uses a variety of charts to compare against to crunch some numbers.
Rather than add each of these into our existing database as its own table, we have opted to leave them as excel sheets and communicate with them directly that way. We decided to use PHP and ODBC for this.

Info on how to achieve this connection with code snippets can be found after the break.
(more…)

Ruby: Mass Parameter Passing

Categories: Ruby
Tags: No Tags
Comments: No Comments
Published on: April 27, 2011

Ever have a method that has a lot of parameters or has optional parameters so you have to structure your input line just right?

For example something like

def my_method(name, age, address = "", height, weight)

end

Normally you’d gather up the variables you want to pass in, confirm some values such as age must be a number, and pass them into the function in order.

What I prefer to do is a technique often referred to as an options hash.
What you do with an options hash collect the data into a hash and pass that into the method instead.
Inside the method, I can then examine what I need and ignore what I don’t.

This has the benefit of moving error checking the data to the method specifically using it rather than checking directly before passing data through.
Also you don’t have to worry about what order you’re passing data in.

The method definition would look more like this:

def my_method(options = {})
    options.each_pair do |key, value|
        # Be sure to inspect each key & value to make sure it conforms to what you expect to be in that field
        #before using it
   end
end

Now this can generate more work within the method due to moving error checking and expanding out default values away from the definition line but it does make it a lot easier when you don’t have a front end that tells you what your method parameters are.

For a little more info on using option hashes especially for optional parameters take a peek at:
http://blog.leshill.org/blog/2009/06/10/default-options-with-ruby.html

Ruby: Array data types and nesting

Categories: Ruby
Tags: No Tags
Comments: 2 Comments
Published on: April 25, 2011

I recently helped a new Ruby programmer with a question involving multidimensional arrays in ruby.

In case anyone finds this useful, here it is:

The premise was to take an existing array and split a string field into an array at its current location.

This is possible because any position in a ruby array can be any type of object including arrays, hashes, or complex classes.

Single Array

We started with a sample array:

test_array = [ 1, " my string of text" ]

By using the .split method we can turn a string into an array of its elements that is broken up, by default, using whitespace as a delimiter.

" my string of text".split
# => ["my", "string", "of", "text"]

Putting this together to edit the sample array in place is simple:

test_array = [1 , " my string of text"]
test_array[1] = test_array[1].split

Multiple Array

Doing this across a multidimensional array is still pretty easy and definitely feels more like ruby and less like a C variant.

First we’ll need a sample array:

sample_array = [[ 1, " my string of text"], [ 2, "my other test string"]]

You see we have two entries in this array that follow the same pattern as the original sample.

The first thing we need to do is to examine the individual innermost array.

sample_array = [[ 1, " my string of text"], [ 2, "my other test string"]]
sample_array.each do |inner_array|
    # Here we are, looking at each array
    # the first inner_array is [ 1, " my string of text"]
end

Now that we’re looking at the inner array in a .each loop we could simply refer to position [1] as we did in the single example.

That is very specific against the location and not a very Ruby style approach.

Instead, let’s examine each item and decide how to alter the array based upon what we’re looking at.

sample_array = [[ 1, " my string of text"], [ 2, "my other test string"]]

sample_array.each do |inner_array|
    inner_array.collect! do |val|
        if val.class == String
            val.split
        else
            val
        end
    end
end

# End result: <span style="font-family: 'Courier New', monospace; font-size: 14px; letter-spacing: 1px; white-space: pre; line-height: normal;">=> [[1, ["my", "test", "string"]], [2, ["my", "other", "test", "string"]]]</span>

Lets take a look at that inner section a little at a time.

The .collect! method replaces the array at the current location with the return of the block being executed. Basically this means whatever happens inside the .collect! block alters the array itself. This is how we’re bypassing directly pointing to the array at position [1] and editing it.

The If .class == String evaluation lets us find the strings we want to split and filter out everything else in the else statement.

The interior of the If statement and the Else statement set up the return for the .collect! statement to alter the array with. Ruby returns the output from the last executed code which happens to be either val.split to split the string or simply val to replace the array’s value with itself.

And that’s that.

The problem was resolved and hopefully taught a little ruby with it.

Syntax Highlighter Test: Hello World!

Categories: Ruby
Tags: No Tags
Comments: No Comments
Published on: April 18, 2011

This is my first blog post here so I need to do a traditional Hello World test!

puts "Hello World!"
page 1 of 1
Welcome , today is Thursday, February 23, 2012