theKindOfMe

January 26, 2012

Rails Assets Pipeline Survival Guide

Filed under: Uncategorized — Tags: , , , , — yasi8h @ 1:50 am

Helpful settings

If you have assets pipeline enabled. By default you need to precompile your assets every time you change something (in production env). Having everything precompiled is cool but this will ask rails compile any assets that are not already compiled.

# Don't fallback to assets pipeline if a precompiled asset is missed
 config.assets.compile = true

Page Specific JS/CSS

If you want some JS/CSS to only be included in a specific set of pages.

  • break the page specific JS/CSS code to different files (ex:- profiles.js)
  • make sure they are not referenced in your manifest file (application.js)
  • add the following code snippets to the necessary files
application.html.erb (your main template)
<head>
 <title>FamousApp</title>
 <%= stylesheet_link_tag "application" %>
 <%= javascript_include_tag "application" %>
 <%= yield :head %>
 <%= csrf_meta_tags %>
</head>
specific_page.html.erb (the template where you want your JS to appear)
<% content_for :head do %>
 <%= javascript_include_tag "profiles" %>
<% end %>

production.rb

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
 config.assets.precompile += %w( profiles.js )

Deploying with Capistrano

This is easy enough

load 'deploy/assets'

If you ever run across this problem:

# Disable warning message about missing dirs 'public/[javascripts|images|stylesheets]'
# src: https://github.com/capistrano/capistrano/issues/79
set :normalize_asset_timestamps, false

January 17, 2012

Note: Test and View available Rails Routes

Filed under: Uncategorized — Tags: , , — yasi8h @ 3:39 am

See all available routes

rake routes

Check route/path/URL helpers (in rails console)

app.the_route_you_want_to_test_path

OR

app.the_route_you_want_to_test_url

January 5, 2012

SQL ‘Group By’ + ‘Order By’ in Mongodb

Filed under: Uncategorized — Tags: , — yasi8h @ 4:50 am

As a newbie to mongodb i was a bit puzzled when i couldn’t find a equivalent to the SQL group by combined with order by in mongodb.

Group

If you just want to go a SQL group by in mongodb you can use the group() function (refer http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Group). however the results you get from group function cannot be sorted using the sort() function. This is because group function does not return a cursor (on which you can sort(), limit()…etc), but a single document.

You can’t sort the document wich is returned by group but you can sort the document in the client side. This is one way to go about doing a ‘group by + order by’. However if you don’t want to sort things in the client side you can use mapreduce.

MapReduce

This is probably not as simple as you would want it to be. But until mongodb supports a one liner for group by + order by function this is the only way to go about it.

You can refer the MapReduce documentation in the official site to get a better understanding about how it works. But if you just want to do a simple group by + order by equivalent in mongodb you can look at the sample bellow.

Mongodb Data Structure
gplus_profiles: id(objectId), have_user_in_circles_count (int)
SQL
SELECT COUNT(id), `have_user_in_circles_count` from `gplus_profiles`GROUP BY `have_user_in_circles_count` ORDER BY 1 DESC
Mongodb
m = function(){
emit(this.have_user_in_circles_count, { count : 1 });
};
r = function(key, values) {
var total = 0;
for ( var i=0; i<values.length; i++ )
total += values[i].count;
return { count:total };
};
res = db.gplus_profiles.mapReduce(m, r, { out : "myoutputt" } );
db.myoutputt.find().sort({value:-1})

Although we have to use mapreduce for the time being, a later version of mongodb will support group by + order by like functionality natively.


	

December 21, 2011

Google Plus and Google Profiles

Filed under: Uncategorized — Tags: — yasi8h @ 2:26 am

Was a bit confused about Google Profiles and Google Plus profiles. A quick note for my self about the two.

  • Both google plus and google profiles seems to be using the same user id
  • A google profile may or may not have a google plus account (if the user didn’t opt for google plus)
  • A user who has signed up for both google profile and google plus have one id and one page for both services.
    • which is the google plus profile page.
  • A user who only signed up for google profile has a google profile page (which is different from a google plus profile page).
  • A user who only signed up for google plus has a google profile page which points to his/her google plus page.
  • So in essences google plus is a upgrade on top of the google profile.

Happy Christmas everyone!

September 27, 2011

Merlion

Filed under: Uncategorized — yasi8h @ 9:25 am
Merlion by thekindofme
Merlion, a photo by thekindofme on Flickr.

The Merlion (Malay: Singa-Laut) is a mythical creature with the head of a lion and the body of a fish, used as a mascot of Singapore. Its name combines “mer” meaning the sea and “lion”. The fish body represents Singapore’s origin as a fishing village when it was called Temasek, which means “sea town” in Javanese. The lion head represents Singapore’s original name — Singapura — meaning “lion city” or “kota singa”.
The symbol was designed by Fraser Brunner, a member of the Souvenir Committee and curator of the Van Kleef Aquarium, for the logo of the Singapore Tourism Board (STB) in use from 26 March 1964 to 1997[1] and has been its trademarked symbol since 20 July 1966. Although the STB changed their logo in 1997, the STB Act continues to protect the Merlion symbol.[2] Approval must be received from STB before it can be used. The Merlion appears frequently on STB-approved souvenirs.

From: Wikipedia(http://en.wikipedia.org/wiki/Merlion)

August 23, 2011

Batch Video Conversion to 3gp using ffmpeg

Filed under: Uncategorized — Tags: — yasi8h @ 6:46 am

Some notes for self reference.

Batch video conversion

Using some a simple loop (in bash)

for f in *.mp4; do ffmpeg -i “${f}” -b 4000k -s 4cif -vcodec h263 -acodec aac -y “${f}_4000.3gp”; done;

Converts all mp4 files in the current folder

Original file name: file_one.mp4

Converted file name: file_one.mp4_4000.3gp

Convert to 3gp

ffmpeg -i file_name -s 4cif -vcodec h263 -acodec aac -y converted.3gp

Convert to with a set bit-rate

When the set bit rate is 4000k (kilo bits)
ffmpeg -i file_name -b 4000k -s 4cif -vcodec h263 -acodec aac -y converted.3gp

Setting resolution

Use the -s flag to set the resoultion. For possible values refer: http://ffmpeg.org/ffmpeg-doc.html

August 17, 2011

Good old days [Photo]

Filed under: Uncategorized — yasi8h @ 10:59 am
good old days by thekindofme
good old days, a photo by thekindofme on Flickr.

Some where near the tanjong pagar market and food centre. From atop of a HDB void deck at night (around 9.30PM) ;).

0.6 sec at f/5.3 45mm with the nikon 18-55 kit lens.

August 5, 2011

Favoritemedium is Hiring!: UI Engineer (based in Singapore)

Filed under: Uncategorized — Tags: , — yasi8h @ 5:34 am

The company i work for: favoritemedium is looking for a new UI talent. Basically if you love hacking JS and CSS, this position is for you. Send in your resume, but more importantly some links to your github and twitter ;)

If i know you (and about your work) you can contact me and i’ll refer you.

Here is the ‘official’ ad.

UI Engineer (Based in Singapore)

We are a successful web and mobile development consultancy seeking to bring on a UI engineer to assist with front-end web development. Our work environment is both fast-paced and fun.

An ideal candidate should have these capabilities:
Ability to communicate effectively in English. Mandarin is helpful but not mandatory.
Very solid HTML and CSS skills. You must live and breathe it.
JavaScript – understand concepts like scoping and declaration hoisting
Understand the differences between browser implementations of HTML, CSS, and JS
Reasonably adept with Photoshop
To be clear, this is not a web design position. It involves client-side development and implementation of designs.

This is a full-time position based in Singapore (S088853).

To apply, please email a resume/CV to hr017@favoritemedium.com and use ‘SG UI Engineer [2011Q3]‘ as the email subject. Include links to Twitter and/or Github accounts, if applicable.

Taking the Plunge: D5100, My first DSLR

Filed under: Uncategorized — yasi8h @ 3:54 am

About two weeks back, i finally took the plunge and brought my first DSLR: D5100. In retrospect i think it was a impulse buy. I was a bit stressed out from a busy schedule and i think this was my escape from all of it. I have been thinking about buying a DSLR for a long time. However i couldn’t justify the expense all this time. But now it seems to be worth it. As photography have given me a reason to be excited about something. A hobby that i desperately needed.

Been a total newbie to photography and with a tiny budget i didn’t have a lot of choices when deciding which camera body to invest it. I think the wise decision would have been to go for a second hand body and spend more cash on some good lenses. But i didn’t do that :P

I had to decide between Cannon 550D/ 600D/ Nikon D5100. All were in the same price range. And here in Singapore, the Nikon was the cheapest. Although else where the cheapest would have been 550D. After going thorough zillion reviews and articles. The general idea i got was 600D was good for video while D5100 was good for photos (as in it produced better quality photos/better low light sensitivity/better sensor).

As my primary aim was photography and also because the Nikon was cheaper, i went for it. I took the bundled body-lens kit which came with a 18-55 lens. I think so far it have been grate. It lets me take good landscape and portraits. However i am always touching its limits. Sometimes its not wide enough, and sometimes it’s not long enough :)

But i guess the important thing is that i am having fun learning photography and experimenting with it. You can follow me on flickr at http://www.flickr.com/thekindofme

June 30, 2011

Fixing foursquare2 gem: NameError: uninitialized constant MultiJson

Filed under: Uncategorized — Tags: , , , — yasi8h @ 12:00 pm

If you get a error similar to the one bellow when you try to use (perform a simple task such as get a venue) from the foursquare2 gem. You are probably missing the multi_json gem.

NameError: uninitialized constant MultiJson
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday_middleware-0.6.5/lib/faraday/response/parse_json.rb:16:in `parse’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/response.rb:17:in `on_complete’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/response.rb:9:in `block in call’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/response.rb:62:in `on_complete’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/response.rb:8:in `call’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/response.rb:8:in `call’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/adapter/net_http.rb:63:in `call’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/request.rb:88:in `run’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/request.rb:28:in `run’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/connection.rb:170:in `run_request’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/faraday-0.6.1/lib/faraday/connection.rb:64:in `get’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/foursquare2-1.1.0/lib/foursquare2/venues.rb:9:in `venue’
from (irb):6
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start’
from /Users/jamesx/.rvm/gems/ruby-1.9.2-p180@snipwits3/gems/railties-3.0.7/lib/rails/commands.rb:23:in `’
from script/rails:6:in `require’
from script/rails:6:in `’ruby-1.9.2-p180 :007 >

So to fix it, just add gem ‘multi_json’ to your Gemfile.

Older Posts »

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.