Technology

So how many different ways you heard from other people of how to charge your gadgets so their battery lives last longer? The most I heard of is to use the battery up completely before charging full. Also there’s saying about keeping them charge between 40% – 80%. So what’s really the ideal way to prolong the battery life?

Finally I found my answer from the LifeHacker, pulling data from the Battery University.

Here’s the summary of what you should do:
1) Perform shallow discharges. Don’t discharge 100%. According to Battery University, partial discharges reduces stress and prolong battery life.

2) Fully discharge it once a month. This is to re-calibrate your device to tell you how long your battery life remains.

3) Keep it cool. A hot battery will degrade in health much quicker than a cool one.

{ 0 comments }

Someone was asking a question about reading files in a zip file without storing and unzipping on the local drive in my work mailing list.  I found the answer quite interesting and will be really useful later in the future.

Here’s sample code to do it:

import java.io.*;

import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
public class UnzipDemo {
  public static void main(String[] args) {
  String zipname = "data.zip";
  try {
    FileInputStream fis = new FileInputStream(zipname);
    ZipInputStream zis = new ZipInputStream(newBufferedInputStream(fis));
    ZipEntry entry;
17.// Read each entry from the ZipInputStream until no more entry found
18.// indicated by a null return value of the getNextEntry() method.
 
  while ((entry = zis.getNextEntry()) != null) {
  System.out.println("Unzipping: " + entry.getName());
  int size;
  byte[] buffer = new byte[2048];
  FileOutputStream fos = newFileOutputStream(entry.getName());
  BufferedOutputStream bos = newBufferedOutputStream(fos, buffer.length);
  while((size = zis.read(buffer, 0, buffer.length)) != -1) {
  bos.write(buffer, 0, size);
  }
  bos.flush();
  bos.close();
  }
  zis.close();
  fis.close();
  } catch (IOException e) {
  e.printStackTrace();
  }
}
}

{ 0 comments }

Setting up Ruby on Rails with MySQL

by fli on November 27, 2011

With the buzz around Ruby on Rail, I have decided to try and start learning.  I hit quite a few road blocks just on my way setting it up.  Here are some lesson learnt:

Installing RoR isn’t hard at all.  I’m on Mac OSX.

1)  Install RoR using the command “gem update rails” in the terminal.

2) Install RubyGem from http://docs.rubygems.org/ and run “ruby setup.rb”

3) Simply run “gem install rails” and basically you’re done.

4) Create a new project by the command “rails new path/to/your/new/application”

5) Go to the new project with command “cd path/to/your/new/application”

6) Start the server with “rails server”.

7) Go to localhost:3000 and it works like a charm with the default page.

http://rubyonrails.org/download is where you can find the full instruction on how to start.

The default setting uses sqlite3 as database.  I want to set it up with mysql.  Since I already have MAMP installed, I tried connecting it to the mysql database there.

I changed config/database.yml replacing the development section with the following:

development:
  adapter: mysql2
  database: ToDo
  host: localhost
  username: ruby
  password: ruby

After changing database.yml, I tried reloading localhost:3000 and got the error “ActiveRecord::ConnectionNotEstablished”

From all the Google research, it seems to be a connection to database issue.  Here are the steps I have to resolve the issue:

Made sure I have mysql installed and made sure I install mysql gem correctly.

1) I did the command ‘sudo gem install mysql’

but I had the following errors:

checking for mysql_ssl_set()… no
checking for mysql.h… no
checking for mysql/mysql.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
–with-mysql-config

I tried using the command to specify the location of the config but since MAMP’s mysql does not have an include folder, it doesn’t work.  Then I found instruction here to recompile MAMP for Ruby.

Here are the steps:

  1. Assumed you already have MAMP installed.
  2. Download the MAMP 1.7.2 source code.
  3. Unzip the source code file.
  4. Open the terminal and go into the source code directory.
  5. Untar the mysql file and go into the untarred directory:
    $ tar -xzvf mysql-5.0.41.tar.gz
    $ cd mysql-5.0.41
  6. This is the Hootbah magic…we’re basically compiling libraries here for the Gem to link against.
    $ ./configure –with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock –without-server –prefix=/Applications/MAMP/Library
    $ make -j2
  7. Copy the compiled libraries into MAMP:
    $ cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql
  8. Copy the MySQL headers into MAMP…Hootbah didn’t do this but I had been doing it earlier trying to get around some missing mysql.h problems, and figured I’d keep doing it:
    $ mkdir /Applications/MAMP/Library/include
    $ cp -R include /Applications/MAMP/Library/include/mysql
  9. Install the Ruby MySQL Gem:
    $ sudo env ARCHFLAGS=”-arch i386″ gem install mysql — –with-mysql-config=/Applications/MAMP/Library/bin/mysql_config

After all these are done, seems like it does the magic in fixing the issues I have before but I started having a new error:

dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle Expected in: flat namespace

dyld: Symbol not found: _mysql_get_client_info Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle Expected in: flat namespace

Trace/BPT trap

Back to research.

Tried a few workaround.  Some posts online suggested to copied or link the .lib and that didn’t work.  That error seems to be saying that something’s wrong with the mysql bundle.

More researching suggested that maybe it’s mysql and ruby not matching.  They need to be both either 32 bits version or 64 bits version.  I double checked the mysql in MAMP and it’s 32 bits version.

So redoing installation again.  I downloaded 64 bits version mysql and installed on my computer.  Reinstall mysql gem using the following command:

sudo env ARCHFLAGS=”-arch x86_64″ gem install mysql2 –version ‘~> 0.2.7′ — –with-mysql-config=/usr/local/mysql/bin/mysql_config

Same error:

ActiveRecord::ConnectionNotEstablished

Of course, just the beauty of copy and paste and missed the very obvious.  Last bit of research, change in Gemfile from mysql to mysql2 (since the gem install command I did was for sql2)

After that,

$rails server

My RoR with mysql is up and running!

Continuing my tutorial, I tried creating the table using the following command after creating the migrate script:

$rake db:migrate

and I got the following errors:

$ sudo rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.6), already activated mysql2-0.3.2. Make sure all dependencies are added to Gemfile.)
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection'
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.3/lib/active_record/railtie.rb:69
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.3/lib/active_record/base.rb:2190
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.3/lib/active_record/railties/databases.rake:6
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `invoke_prerequisites'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/francessmli/.gem/ruby/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => db:migrate => db:load_config

Just with a bit of research and using the following command to see more details of what’s wrong:
$rake db:migration –trace
Turned out the mysql is not the correct version.

In order resolve this, I did the followings:

1) $ gem uninstall mysql2
2) $ sudo env ARCHFLAGS=”-arch x86_64″ gem install mysql2 –version ‘~> 0.3.6′ — –with-mysql-config=/usr/local/mysql/bin/mysql_config
3) Modified Gemfile from “gem ‘mysql2′,’0.2.7′” to “gem ‘mysql2′,’0.3.6′”
4) $ bundle install

Off I go with my RoR tutorial!

{ 1 comment }

Upgrading iPhone 2G with iOS 4 ( Trick to resolve iTune cannot restore from last backup because the backup session failed )

September 28, 2011

“Successfully” upgraded iPhone 2G to iOS 4 and solving iTune cannot restore from last backup because the backup session failed error.

Read the full article →

See your doctor virtually for a cost

September 27, 2011

Rite Aid rolled out virtual physician visit for a cost.

Read the full article →

What’s the difference between Adwords vs Adsense?

May 7, 2011

What’s the difference between Adwords vs Adsense?

Read the full article →

Storing leads to Salesforce with CQ form

May 6, 2011

Today I need to find out how to store lead information from Adobe CQ to Salesforce. I understand that Salesforce is a very powerful tools with abundant API to integrate with other system so I started looking at what Salesforce can provide for this simple task. Salesforce does make it really simple by having all [...]

Read the full article →

OpenID vs OAuth

April 25, 2011

Details of what OpenID and OAuth are.

Read the full article →

Credit Card 2.0 – the MultiAccount and Hidden cards

October 23, 2010
Card 2.0

Combining more than one account into one card and technology to hide the credit card number before entering your pin into the card itself before use.

Read the full article →

And the games are back on Facebook – LOLapps games are unblocked finally

October 18, 2010
Critter Island, LOLapps

After a weekend of unavailable services, LOLapps games are back on fixing up the user ID leakage issue.

Read the full article →