Ruby GC Variables

The following are some helpful env vars to tweak in order to manage the GC behavior for your app:

RUBY_HEAP_MIN_SLOTS (default is 10k): Push this higher so that it does not have to ask the system for more slots.

RUBY_GC_MALLOC_LIMIT:  Bump this up.  This will trigger GC minor to be triggered. 

RUBY_GC_HEAP_FREE_MIN : THE NUMBER OF HEAP SLOTS MADE AVAILABLE AFTER GC IS RUN.

Rules I like

Building process.

0. Read requirement (if one exists, these days everyone laughs at requirements)

1. Write the test.

2. Write some psuedo code to model the real code (these are my code comments).

3. Run test and of course it fails

4. Write real code under the psuedo code 

5. Make tests pass.

Tagged , ,

oooh! Select me

Selects options have always been a mystery to me….  Here is an example that I got working.  The include_blank is pretty useful, it sets the value to “” and shows ‘none’

 =f.select :food,  ["burrito", "taco", "yums"], :selected => ("#{@my.foods.blank?}" || 'none' ), :include_blank => 'none'
24
Tagged

in JS objects are hashes (Key//Values)

in JS objects a…

Example of defining a set of methods using via an array

class Dyn
  THINGS = %w(bah no mo)

 

  THINGS.each do |t|
        define_method t do
         p t.inspect
      end
end

 

end

Hook method

module MyMixin
  def self.included(base) #Hook fired when module is included
     base.extend(ClassMethods) #Allows for the addition of modules class methods to the base (includer).
  end

  def kill 
    "killme"
  end

  module ClassMethods 
    def x
      "x()"
    end 
  end
end

class B 
  include MyMixin
end

b = B.x #Modules class meth called
k = B.new
p k.kill #Modules instance meth called
p b
Tagged

Need to pull data from another env.

class TestBar < ActiveRecord::Base
establish_connection "development"
set_table_name :bars
set_primary_key :bar_id
end

establish_connection

Establishes the connection to the database. Accepts a hash as input where the :adapter key must be specified with the name of a database adapter (in lower-case) example for regular databases (MySQL, Postgresql, etc):

set_table_name – Sets the table name. If the value is nil or false then the value returned by the given block is used.

set_primary_key – Sets the name of the primary key column to use to the given value, or (if the value is nil or false) to the value returned by the given block.

HUGE PROPS TO http://railsforum.com/viewtopic.php?pid=148737

Validation Uniqueness Of

By default the allow_nil will be set to false.  Be sure to set that to true if you want to validate only when something is passed to you.

Rails 3.1 installing Lightbox Jquery plugin.

Download the plugin: http://leandrovieira.com/projects/jquery/lightbox/

In /vendor/assets

create a dir called javascript
and another called stylesheets. Move the lightbox.min.js to the newly created javascripts folder. and Lightbox.css to the stylesheets folder.

vendor/assets
|–stylesheets
|–lightbox
|–javascripts
|–lightbox

Add the file paths to application.js and application.css.  Note the order of how you enter them.

ex. application.js

//= require jquery
//= require jquery_ujs
//= require lightbox/lightbox

ex application.css

*= require_self
*= require lightbox/lightbox
*= require_tree .

Be sure to do config.serve_static_assets = true in production.rb so that assets will get served out of public/assets in production.

Run rake assets:clean followed by rake assets:precompile

Tagged

Refresh git after adding a .gitignore.

Be sure to commit your changes and then adding a .gitignore file to your project.

If you are doing this mid project use

git rm –cached <filename> in order to manually untrack the files.

KEEP IN MIND THAT RUNNING THAT COMMAND WITH A FILE THAT HAS CHANGES IN IT WILL CAUSE IT TO GET LOST.