Categories
ruby on rails

Autorun mess up bundle install

I still feel like working with rails in Linux feel easier and faster. What’s with all the homebrew thing in Mac, feel like you have to go through a lot of troubles just to complete something simple. But working with rails in Windows is another story altogether. Initiatives like Railsinstaller and Devkit help a lot to get Windows to be less of a pain, but still…

So I have install railsinstaller, and Devkit come installed with it. And I have things running pretty normal, till lately I try to create a new rails apps, doing a bundle install lead to error saying

Gem files will remain installed in C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9 .1/gems/json-1.7.6 for inspection. 
Results logged to C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/json-1.7. 6/ext/json/ext/generator/gem_make.out An error occured while installing json (1.7.6), and Bundler cannot continue. Make sure that gem install json -v '1.7.6' succeeds before bundling.

I tried to reinstall railsinstaller, and manually install Devkit. No working. Then tried to uninstall railsinstaller, and have ruby installer manually, then Devkit, make sure Devkit path is under ruby root, still the problem persist. Finally I found the solution in stackoverflow, from a link in treehouse’s blog . The thing is Devkit doesn’t work with Autorun interfaces, so if you have previously have this setup, in my case it was the I setup for syntax highlighting in command prompt, then you will have to remove it.

Just type this into command prompt

REG QUERY "HKCU\Software\Microsoft\Command Processor"
REG QUERY "HKLM\Software\Microsoft\Command Processor"

Should get something like below

HKEY_CURRENT_USER\Software\Microsoft\Command Processor
    CompletionChar        REG_DWORD    0x9
    DefaultColor          REG_DWORD    0x0
    EnableExtensions      REG_DWORD    0x1
    PathCompletionChar    REG_DWORD    0x9

These columns actually stand for Key, Type and Value. If there is a Key named AutoRun, then this could be the root cause of the problem. In my case, I think the Autorun key was set when I setup ansicon.
Run this to remove it,

REG DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun

Close command prompt, and bundle install again in a new command prompt session, things should work.

Categories
ruby on rails

Futnotes running locally

Redo the whole process. Clone repo again, bundle install now work right away, as all the prerequisites are there.
Instead of running rake tasks separately, which fail previously with long list of errors

rake db:create:all
rake db:migrate
rake db:seed

I will just do this, which is a shortcut for rake db:create; rake db:schema:load, and rake db:seed

rake db:setup

And it work!

Precompile Assets,

rake assets:precompile

lead to an error saying “Segmentation fault while running ‘rake assets procompile'”. A suggestion in stackoverflow saying that the rootcause might be execjs, change to therubyracer gem should solve the problem. Even though there is no execjs gem dependency in the gemfile, I still add in therubyracer gem, bundle install again, now rake assets:precompile just work, and I have futnotes running locally. Now off to get the test done

Categories
ruby on rails

Futnotes – setting up the repo

Cloning the repo

git clone https://github.com/Futnotes/dev_test-2.git devtest

Mixtures of errors doing bundle install though
First it is capybara

Using capybara (1.1.2) 
Installing capybara-webkit (0.12.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

According to these sources thoughtbot and stackoverflow qt need to be installed first, before install capybara.
To install qt, you must link to libpng, simply link to linpng will fail due to permission,

Error: Could not symlink file: /usr/local/Cellar/libpng/1.5.13/lib/pkgconfig/libpng15.pc
/usr/local/lib/pkgconfig is not writable. You should change its permissions.

To fix that

sudo chown -R kahfei /usr/local/lib/pkgconfig

then only follow by command below

brew update
brew link libpng
brew install qt

bundle install still fail though

An error occurred while installing rmagick (2.13.1), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.

It seems that lot of people having this same problem. Some of the suggestion work for some people, but none of it fixed my problem. Apparently this is a rmagick bug, as it does not support the newer version of ImageMagick. rmagick has not been updated for two years, so if there is an option, change to other gem to work with image, like minimagick

After hours of scouring the internet, and trying a few different approaches, using the magick-installer to install ImageMagick, then

bundle install

work again. No actually I lie,  bundle install yield another error

ERROR: While executing gem … (ArgumentError) marshal data too short

There are suggestions to remove ~./gem folder altogether and reinstall all the gem. But in my case, bundle install work on other rails apps, just not this one. So I clone again the repo to a new folder, now bundle install work!

Now creating development, testing and production environment. I already have postgresql installed locally, so I will use postgresql, my database.yml looks something like this

development:
adapter: postgresql
encoding: unicode
database: futnotes_development
pool: 5
username: kahfei
password: 
test:
adapter: postgresql
encoding: unicode
database: futnotes_test
pool: 5
username: kahfei
password: 
 
production:
adapter: postgresql
encoding: unicode
database: futnotes_production
pool: 5
username: kahfei
password:

now to create them

rake db:create:all

All three database created

rake db:migrate

with a long list of errors, it start with something like this

PG::Error: ERROR:  column "position" does not exist
LINE 1: ...RE "competitions"."name" = 'Premiership' ORDER BY position, ...
Categories
ruby

require file from same directory in ruby

Requiring a file sitting in the same directory wouldn’t work with this

require 'something'

Seems like Ruby 1.9 remove current directory from load path as I read from Stackoverflow

To make it work you could

require './something'

or use require_relative,

require_relative 'something'

The thing is,

load 'something.rb'

still work. So does that mean load and require have different load path?

Categories
web

Great advise

Categories
design

Closing the gap

Ira Glass on Storytelling from David Shiyang Liu on Vimeo.

Love this…

Categories
ruby

Regex hammer time

When you have a hammer, you see everything as nails.
A very true message from Dive into Python 3,

Regular expressions are extremely powerful, but they are not the correct solution for every problem. You should learn enough about them to know when they are appropriate, when they will solve your problems, and when they will cause more problems than they solve.

But it is easy to fall into the trap of using regex for everything.
I need to find the last string from a path, where

path = "d:/some/directory-with dash-and space"

So here is how I try to get the last string in a path, with regex

path.match(/\w*$/)

trying to capture any word characters at the end of the string with \w*$, but only captured the last word “space”, not good.

path.match(/(\s|\w)*$/)[0]

to match either whitespace (\s) or word characters (\w) at the end of the string, the result is “and space”, dashed is not captured, not good.

path.match(/[^\/]*$/)

[^\/] to take in everything except “/”, result is “directory-with dash-and space”, it works!

Only later I found out there is a really simple way to do this

File.basename(path)

will actually give you “directory-with dash-and space”. Plus, it will ignore ending slash if there is any.
Duh!

Categories
ruby

ruby tonic

This should taste good.

 

Categories
ruby

RubyMonk

Finally. Thank you master.

Categories
web

Incredibox, background music for programming

incredibox

Found this incredibox from hacknernews few days ago, there is a neat interface lets you drag and drop different effects, melodies, beats and voices to create your own remixes. But the title in hackernews is saying “Background music for programming”, which is a lie. The thing is so fun to play around with, you immediately forgo your coding, and keep tinkering with incredibox