David Chua

Random Ramblings from a Curious Geek 

Rawjak!

Someone passed a link to this awesome local psychedelic mix on my twitter and I absolutely love it!

Suddenly, I feel like I'm taken back to my polytechnic days where I used to keep track of all the happenings in the electronic music scene. I wonder why I stopped doing so in the first place.

Anyway, the site's called Rawjak.com and its one of the growing population of local djs publishing their content on their websites. Rawjak is now bookmarked next to Meshradio in my browser.

If you guys got any another recommendations on where to get local dj mixes, do holla at the comment section below.

Loading mentions Retweet

Comments [0]

Facebook Be-gone

I've finally done it.

I've committed Facebook Suicide. As of 9pm (thereabouts) on the 12th of Janurary 2010, I've deactivated my Facebook Account. Removing myself from Facebook's vast network after years of keeping in contact with friends, families and acquaintances is not an easy task, and in a way, I'm glad that I've done it.

So this is it, Day 1 of a new Facebook-less existence.

Lets hope I can last for more than a week at least.

Loading mentions Retweet

Comments [0]

Happy Wisdom 2010!

Just got back from a wisdom tooth extraction at National Healthcare Group's Hougang Dentalcare clinic.

This is the first time I'm extracting my teeth at a government clinic and I'm very impressed at the level of professionalism the staff from the call center to the dental surgeon has shown.

I wouldn't mind going back there again.

I might have to because after extracting my 3rd wisdom tooth today, I found out I still have one more just chilling in my left lower jaw.

I also found out my body reacts to anesthesia much slower than when I was younger. Luckily Dr Tan Mei Na was pretty professional always checking if I was in pain and adding more jabs when needed.

So there it is. Ending 2009 with a wisdom tooth extraction.

Here's 's to a non-teethy 2010.

Happy New Year folks!

Loading mentions Retweet

Comments [0]

GSM Cracked - 26th Chaos Communications Congress

The annual Chaos Communications Congress is barely into day 2 of its 26th meeting and the folks have released published open source instructions for cracking the A5/1 mobile telephony encryption algorithm and for building an IMSI catcher that intercepts mobile phone communication. GSM, you're no longer safe!

The Global System for Mobile Communications (GSM)
standard for digital mobile phone networks, which is used by around
four billion people in 200 countries, is quite insecure, explained
cryptography expert Karsten Nohl in front of a large audience of
hackers. While this has been known in academic circles since 1994, the
evidence now produced leaves "no more room for playing hide and seek"
said Nohl.

 Kudos.

Loading mentions Retweet

Comments [0]

Socialism, Fear, and the Singapore Angle

I noticed, the newspapers keep calling people like Dr Poh Soo Kai and the others detained under the infamous Operation Coldstore, as 'socialists of their time' as though socialism is a bad thing. A quote from the recent Straits Times article, writes "Dr Poh admits he is a socialist, even a Marxist, but denies being a communist, that is, being a card-carrying member of the Malayan Communist Party." (As I do not have access to the ST Digital Archive, here's a repost of the article on The Temasek Review)

Remember folks, socialism is not the same as communism and is a respected form of political idealogy practiced by many European and North American nations like France, Germany and Canada for example. I think the biggest irony of all is that the newspapers try to subtly demonize 'socialism', when its political masters, the People's Action Party is by-and-large a socialist party. The name of the party itself reveals its socialist roots.

So what went wrong? What happened to PAP or did the newspapers suffer some kind of amnesia? Why the attempt to demonize and create fear over 'socialism'? Is it because the recent public attention to books like the 'Farjah Generation' which brings 'Operation Coldstore' to the public eye for scrutiny? Is it because the whole reason these men were detained for over decades is because of their alleged communist ties, which could never be proven, but still detained anyway?

In the United States, Conservative Republicans are constantly using 'socialism' as an tool and reason to demonize President Obama's policies. Is the same thing happening in our very own local newspapers?

At the end of the day, fear does nothing to the political process. It destroys ideas and kills the spirit. Fear, is the product of old politics. After 4 decades of being constantly told to be afraid of, racial disharmony, riots, the destruction of Singapore's economic livelihood, isn't it time to stop being afraid?

I'll leave you with a famous quote by our very own Minister Mentor:

"Repression, Sir is a habit that grows. I am told it is like making love-it is always easier the second time! The first time there may be pangs of conscience, a sense of guilt. But once embarked on this course with constant repetition you get more and more brazen in the attack. All you have to do is to dissolve organizations and societies and banish and detain the key political workers in these societies. Then miraculously everything is tranquil on the surface. Then an intimidated press and the government-controlled radio together can regularly sing your praises, and slowly and steadily the people are made to forget the evil things that have already been done, or if these things are referred to again they're conveniently distorted and distorted with impunity, because there will be no opposition to contradict."

- Lee Kuan Yew as an opposition PAP member speaking to David Marshall, Singapore Legislative Assembly, Debates, 4 October, 1956

Loading mentions Retweet

Comments [0]

10 Steps to getting role authorization working on your rails project

How to get declarative_authorization working on a brand new rails project in 10 steps

1) In your config/environment.rb, Add the line

config.gem "declarative_authorization", :source => "http://gemcutter.org"

2) Do a rake gems:install

3) Create a Role model

./script/generate model Role title:name

4) In your migration file that comes with your model, reference the role table with your user model (replace the name of the model as necessary)

t.references :user

5) In your User model, create a has_many :roles association

6) In your Role model, create a belongs_to association

7) Create a authorization file that will contain your authorization file. in config/authorization_rules.rb

authorization do 
  role :admin do
    has_permission_on :controller_or_model, :to => :method
  end
end

8. Set the role_symbols in your User model. Add the following method:

def role_symbols
  (roles || []).map {|r| r.title.to_sym}
end

9. rake db:migrate

10. Assign roles to your User by @user.roles.create(:title => 'admin') and you're done!

Bonus

11. Add "filter_access_to :all" in all your controllers that needs the authorization check

12. You'd need to set your current_user to Authorization. If you're using Authlogic, you can do the following in your ApplicationController

Add the following code near the top ...



  before_filter :set_current_user

  def set_current_user
    Authorization.current_user = current_user
  end


13. To have Declarative Authorization send a custom message and/or redirection upon user accessing a controller/model without proper authorization, in the same ApplicationController, add the following public method



def permission_denied
  flash[:error] = "You shouldn't be here! hmmpft!"
  redirect_to "/"
end


 

Loading mentions Retweet

Comments [0]

Note to self.

Never name your controller actions 'request'. It will introduce you to a world of pain.

http://wiki.rubyonrails.org/rails/pages/ReservedWords

Loading mentions Retweet

Comments [0]

Authlogic functional testing embarrassment

When running functional tests with authlogic, remember to put setup :activate_authlogic at the top of every controller you're testing that has authentication. I spent 12 full hours trying to debug this, only to figure this out. Funny thing is it just didn't occur to me, when I've used that line before in another controller test.

Loading mentions Retweet

Comments [0]

Coloring your tests in Rails

Having learnt about unit testing in rails during my short internship stint at Novell, I've always thought that rake tests would always have colored output. Little did I know that you'd have to install a gem to do so.

So, to get your rake test output in a more readable format, install the gem 'redgreen'

gem install redgreen

and add the following

require 'redgreen'
 

at the top of your test_helpers.rb.

This would return red/green/yellow colored output on your tests to indicate whether it has passed, has errors or failed. Makes running test much more easy on the eyes :)

Loading mentions Retweet

Comments [0]

Holding current rails location for future redirection

I always have this problem of redirects not going back to the exact page that I want it to. After chatting with some of the rails developers at #rubyonrails on freenode, they've provided me with this handy code snipplet to save the current page location temporary and after redirecting it, destroy that temporary location.



# We can return to this location by calling #redirect_back_or_default.
 def hold_location
  session[:return_to] = request.request_uri
 end

 # Redirect to the URI stored by the most recent hold_location call or
 # to the passed default. Set an appropriately modified
 #   after_filter :hold_location, :only => [:index, :new, :show, :edit]
 # for any controller you want to be bounce-backable.



 def redirect_back_or_default(default)
  redirect_to(session[:return_to] || default)
  session[:return_to] = nil
 end


Put this in your ApplicationController and you can just call a "hold_location" method call anywhere in your code and do a simple redirection later with a "redirect_back_or_default" call.

Cheers.

Loading mentions Retweet

Comments [0]