29 Jul 2009, 12:41pm
Linux:
by bseanvt

leave a comment

Chunk an FLV File into Multiple Parts

The format is as follows

ffmpeg -i <input file> -ss <starting point> -t <length of capture> <output file>
ffmpeg -i Input_File.flv -ss 00:00:00 -t 00:10:00 Output_Filename.flv

http://www.surfthedream.com.au/blog/Archives/november-2008/how-to-split-a-movie-file-into-multiple-parts

David Heinemeier Hansson – Ruby on Rails, Startups, Culture

YouTube Preview Image
29 Jul 2009, 1:19am
Ruby on Rails:
by bseanvt

leave a comment

Ruby on Rails vs. PHP in a Nutshell

YouTube Preview Image

Nested Has_one Relationship with Fields_for and Attr_accessible in Model Class

To make child attributes accessible to your model through a nested forms (Rails 2.3) you’ll need to add the “#{child_class}_attributes” to the attr_accessible method in your parent class. If you don’t use attr_accessible in your parent model (you would do this to restrict certain attributes to be accessed via a web form) then you should be all set.

Below is an example where User has_one Profile with the favorite_color attribute being set/updated in the nested form.

class User < ActiveRecord::Base
  has_one :profile #child class
  accepts_nested_attributes_for :profile
  attr_accessible :profile_attributes # the format is the child_class followed by the "_attributes"
end

And the form would like this...

<% form_for @current_user do |f| %>
   <% f.fields_for :profile do |profile| %>
     <%= profile.text_field :favorite_color %>
  <% end %>
<% end %>
25 Jul 2009, 9:07pm
Linux
by bseanvt

leave a comment

Joining Technorati

yuw3dqxzp2

Nested Attributes in a Form for Has_One Model Association in Rails

Just for reference…

class Member < ActiveRecord::Base
    has_one :member_profile
    accepts_nested_attributes_for :member_profile
end


<% form_for @member do |f| -%>
       <%= f.label :fullname %> <%= f.text_field :fullname %>
	<% f.fields_for :member_profile, @member.member_profile do |member_profile|%>

<%= member_profile.label :about %><%= member_profile.text_field :about %>

<%= member_profile.label :favorite_color %><%= member_profile.text_field :favorite_color %>

	<% end %>

Destroy Children In Rails 2.3

In the parent class place the following code

has_many :posts, :dependent => :destroy

This used to be accomplished with

has_many :posts, :dependent=>true

Check out the Rails docs for more information http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

Make Rails Lib Module Methods Available to Views

If you create a module in the lib/ directory of your Rails application you won’t have access to those methods in your views. If you don’t want to put those methods in a helper file, you need to add a method to your module that makes them available for you views like so…

#in lib/my_module_name.rb
module MyModuleName
  def my_method_for_views
     #logic...
  end
  def self.included(base)
    base.send :helper_method, :my_method_for_views if base.respond_to? :helper_method
  end
end
11 Jul 2009, 11:56pm
Ruby on Rails:
by bseanvt

3 comments

Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task

If using Sphinx, you need to refresh indexes when you add new content to your database. This is fairly easy to do by hand

rake thinking_sphinx:index RAILS_ENV=production

But if you want to automate this and use a cron, remember to set the PATH, SHELL and RAILS_ENV variables for your job. The environment isn’t the same when you’re doing it by hand and your index will fail silently :(

You find your specific PATH and SHELL info like so

echo $PATH
echo $SHELL

To get into the cron and set your schedule

crontab -e
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
SHELL=/bin/bash
RAILS_ENV=production

# re-index production sphinx every 15 minutes
*/15 * * * * root cd /var/www/rails_app && /usr/local/bin/rake thinking_sphinx:index >> /dev/null 2>&1

More information available here

http://heimdull.blogspot.com/2009/05/journey-with-thinking-sphinx-and-crond.html

http://groups.google.com/group/thinking-sphinx/browse_thread/thread/5451458fae7d6124

11 Jul 2009, 11:48pm
Linux:
by bseanvt

leave a comment

How to Get Your User's SHELL and PATH Information

How to find your user SHELL and PATH on Linux

echo $PATH
echo $SHELL

Which will print the paths to the screen

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
/bin/bash