Friday, August 30, 2013

Effect of Indexes (on a database table's Size)

sp_spaceused
-----------------
sp_spaceused in Sql Server can be used to find a table's size.
Comparing a table's size before & after creating an index can be done using it.

Thursday, August 29, 2013

Google - search by specifying Time

Append the following to the URL -

&tbs=qdr:h   -- past Hour
&tbs=qdr:d   -- past Day
&tbs=qdr:m  -- past Month
&tbs=qdr:y   -- past Year

Sunday, August 25, 2013

Rails - disable sql logging (to not show in "rails server" terminal)

"rails server" log, to become useful, should not have sql lines showing up in between "rendered", "redirected", "Start GET", "Processing by" lines (which are very important at the time of development).

http://stackoverflow.com/questions/7759321/disable-rails-3-1-sql-logging
To turn it off:
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
To turn it back on:
ActiveRecord::Base.logger = old_logger
(We can do the above in "rails console")

Friday, August 23, 2013

tail & grep

1. search for 1 word

http://stackoverflow.com/questions/7161821/how-to-grep-a-continuous-stream
Turn on grep's line buffering mode.
tail -f file | grep --line-buffered   my_pattern

tail -f /home/saiponduru/dev/pyr/pyr-greenzone/log/development.log | grep --line-buffered Rendered

2. search for multiple words

http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/
$ grep 'warning\|error\|critical' /var/log/messagesTo just match words, add -w swith:
$ grep -w 'warning\|error\|critical' /var/log/messagesegrep command can skip the above syntax and use the following syntax:
$ egrep -w 'warning|error|critical' /var/log/messages
I recommend that you pass the -i (ignore case) and --color option as follows:
$ egrep -wi --color 'warning|error|critical' /var/log/messages

tail -f /home/saiponduru/dev/pyr/pyr-greenzone/log/development.log | egrep -wi --line-buffered 'rendered|account'
OR
From pyr-greenzone directory -
tail -f ./log/development.log | egrep -wi 'rendered|account'


Thursday, August 22, 2013

Rails - pass additional parameters while using redirect_to

http://stackoverflow.com/questions/5599698/rails-passing-parameters-in-a-redirect-to-is-session-the-only-way
redirect_to(new_user_path(:notice => 'Please register as a new user', :uid => 'ABCD'))
The params you want to pass are arguments to the new_user_path method, not the redirect_tomethod.

Thursday, August 15, 2013

1 PC -> Multiple PCs

New concepts - Mob Programming, No Estimates

Mob Programming:
http://codebetter.com/marcushammarberg/2013/08/06/mob-programming/
http://mobprogramming.org/

No Estimates:
https://twitter.com/search?q=%23noestimates
http://zuill.us/WoodyZuill/category/estimating/

Mob Programming & No Estimates:
http://mobprogramming.org/how-does-the-mob-get-away-with-no-estimates/


TeamViewer for Mob Programming
- can be used for paired programming (i.e. 2 persons).
- in Meeting mode, we can give control to meeting-participants. This works in the free version also, so TeamViewer can be used for 'mob programming'.

Windows Phone App Studio

http://www.kunal-chowdhury.com/2013/08/windows-phone-app-studio.html
http://www.kunal-chowdhury.com/2013/08/how-to-build-rss-feed-reader-using.html
Microsoft has recently launched a tool called “App Studio” which will allow you to build a Windows Phone app without any programming skill. 
....
Windows Phone App Studio lets you easily build apps for immediate publishing, testing and sharing with clients, co-workers, and friends. When you're ready to add advanced programming features or UI changes, the Windows Phone App Studio also generates source code for you to download. 
 

Javascript Design Patterns

(Have to read this)
http://www.codeproject.com/Articles/636699/JavaScript-Design-Patterns

Talks about :

  • Simulated Classes
  • Module Pattern
  • Revealing Module Pattern
  • Lazy functions

Thursday, August 8, 2013

git - see commits in a branch (that are not in another branch .e.g. master)

To see commits that are there in mybranch but not in master:
git  log  master..mybranch  --oneline

To see commits that are there in master, but not in mybranch:
git  log  mybranch..master  --oneline

git - copy a file from another branch

http://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch
git checkout master               # first get back to master
git checkout experiment -- app.js # then copy the version of app.js 
                                  # from branch "experiment"
Basically, if we are copying a file, say file1.js from FROM-B branch to TO-B, then:

git  checkout  TO-B
git  checkout  FROM-B  --  file1.js

git - diff files between 2 branches

To diff a single file in 2 branches:
git diff mybranch master -- myfile.cs
To diff all files in 2 branches:
    git diff mybranch master 

Learn HTML using a game

Sunday, August 4, 2013

HTML, CSS related: Show Div on 'hover' with only CSS

I have seen empty <a> followed by div elements sometimes (like below):
<a>Menu Item</a>
<div>
   some stuff
</div>

The reason for the empty <a> elements is probably the below: 
http://stackoverflow.com/questions/5210033/show-div-on-hover-with-only-css
Assuming HTML4, with this markup:
<a>Hover over me!</a>
<div>Stuff shown on hover</div>
You can do something like this:
div {
    display: none;
}

a:hover + div {
    display: block;
}
This uses the adjacent sibling selector, and is the basis of the suckerfish dropdown menu.
HTML5 allows anchor elements to wrap almost anything, so in that case the div element can be made a child of the anchor. Otherwise the principle is the same - use the :hover pseudo-class to change thedisplay property of another element.

jsfiddle example:

Sunday, July 28, 2013

jquery - .prop() vs .attr()

http://api.jquery.com/prop/
http://stackoverflow.com/questions/5874652/prop-vs-attr/5884994#5884994
A DOM element is an object, a thing in memory. Like most objects in OOP, it has properties. It also, separately, has a map of the attributes defined on the element (usually coming from the markup that the browser read to create the element). Some of the element's properties get their initial values fromattributes with the same or similar names (value gets its initial value from the "value" attribute; hrefgets its initial value from the "href" attribute, but it's not exactly the same value; className from the "class" attribute). Other properties get their initial values in other ways: For instance, the parentNodeproperty gets its value based on what its parent element is; an element always has a style property, whether it has a "style" attribute or not.


Ruby - how to access properties using 'string' version of property-names

(2012 question/answer)
http://stackoverflow.com/questions/12136262/ruby-get-set-an-objects-property-using-a-string-symbol
car.color
car.send("color=", value)
(2009 question/answer)
http://stackoverflow.com/questions/903763/how-to-convert-from-a-string-to-object-attribute-name
irb> example_customer.name
#=> "Evagation Governessy"
irb> field = 'name'
#=> "name"
irb> example_customer.instance_variable_get(field)
NameError: `name` is not allowed as an instance variable name
from (irb):8:in `instance_variable_get`
from (irb):8
irb> example_customer.instance_variable_get('@'+field)
#=> nil
irb> example_customer.send(field)
#=> "Evagation Governessy"
irb> example_customer.send(field+'=', "Evagation Governessy Jr.")
#=> "Evagation Governessy Jr."
irb> example_customer.send(field)
#=> "Evagation Governessy Jr."
irb> example_customer.name
#=> "Evagation Governessy Jr."
So you can see how #send(field) accesses the record information, and trying to access the attributes doesn't. Also, we can use #send(field+'=') to change record information. 

Ruby - strings - difference between using single quotes & double quotes


https://rubymonk.com/learning/books/1-ruby-primer/chapters/5-strings/lessons/31-string-basics
A String literal created with single quotes does not support interpolation.
The essential difference between using single or double quotes is that double quotes allow for escape sequences while single quotes do not. What you saw above is one such example. “\n” is interpreted as a new line and appears as a new line when rendered to the user, whereas '\n' displays the actual escape sequence to the user.
Example of interpolation:
a = 1
b = 4
puts "The number #{a} is less than #{b}" 

Thursday, July 25, 2013

Captcha related

Have to read this -
http://15daysofjquery.com/safer-contact-forms-without-captchas

Then this:
http://stackoverflow.com/questions/8472/practical-non-image-based-captcha-approaches

Have to see if we can use Raphael.js to draw captchas (Not sure if we can provide the same kind of functionality as reCaptcha or not i.e. audio etc)

Tuesday, July 23, 2013

Rails - newer property syntax

When using the newer property syntax, there should not be a space between the property-name and colon (:)

i.e.
class: 'icon-picture'     --> correct
class : 'icon-picture'    --> incorrect 

Observe the space before the colon (:) in the incorrect line

Rails - passing html5 'data' attributes to link_to

In the example in the previous post, notice the syntax that is used to specify key & value for data-toggle

2 ways:
(from http://stackoverflow.com/questions/2134702/ruby-1-9-hash-with-a-dash-in-a-key )

(I)"data-toggle" => 'modal'
<%= link_to " Change Image", "#modalDiv1", { class: 'icon-picture', "data-toggle" => 'modal' } %>

i.e.
1. use double quotes (i.e. string instead of symbol)
2. use hash-rocket syntax (=>) instead of colon (:) syntax

It seems we cannot use the new colon syntax with keys that contain a hyphen (-) as in data-toggle

(II)data: { toggle: 'modal' } 
<%= link_to " Change Image", "#modalDiv1", { class: 'icon-picture', data: { toggle:'modal'} }%>

i.e.
1. Specify a 'data' hash for 'data' attributes:

Rails - Bootstrap Modal Dialog (pre-loaded & ajax)

Thursday, July 18, 2013

Rails - class_name

When trying to establish relationship between 2 models, we have to specify :class_name if 'module' is different

/app/models/abc/address.rb
module ABC
class Address < ActiveRecord::Base
belongs_to :user
                attr_accessible :user_id, :address1, :address2, :city, :country, :state, :zip, :is_primary_address
         end
end

/app/models/user.rb
class User < ActiveRecord::Base
       has_many :addresses, :class_name => ABC::Address
       ...
       ...
end

Sublime Text - Color Schemes (with White background)

Eiffel
Mac Classic
Dawn

Sunday, July 14, 2013

Rails - Difference between attr_accessor and attr_accessible

http://stackoverflow.com/questions/3136420/difference-between-attr-accessor-and-attr-accessible
attr_accessor is a ruby method that makes a getter and a setter. attr_accessible is a Rails method that allows you to pass in values to a mass assignment: new(attrs) or up update_attributes(attrs).
Here's a mass assignment:
Order.new({ :type => 'Corn', :quantity => 6 })
You can imagine that the order might also have a discount code, say :price_off. If you don't tag :price_off as attr_accessible you stop malicious code from being able to do like so:
Order.new({ :type => 'Corn', :quantity => 6, :price_off => 30 })
Even if your form doesn't have a field for :price_off, if it's in your model it's available by default. This means a crafted POST could still set it. Using attr_accessible white lists those things that can be mass assigned.
http://stackoverflow.com/questions/4838399/how-i-can-set-attr-accessible-in-order-to-not-allow-access-to-any-of-the-field
By default the attributes are all attr_accessible (which means they can be set my mass-assignment).
  • attr_accessible - only this list of attributes can be set by mass-assignment (white-listing).
  • attr_protected - these attributes cannot be set by mass-assignment (black-listing).
  • attr_readonly - these attributes cannot be set except for when the record is created.
Beginning with Rails 3.1, the following configuration option is available to disable mass-assignment by default for all models until you explicitly call attr_accessible or attr_protected:
config.active_record.whitelist_attributes = true

Rails Routing - path_names

Using "path_names" :

http://localhost:3000/users/sign_up
=>
http://localhost:3000/users/register

Friday, July 12, 2013

Rails - customizing 'scaffold' generator

In 'lib' folder, create the following folders: templates > erb > scaffold

Create index.html.erb and other files here (i.e. in 'scaffold' folder)
(The default versions of the above files that come with 'rails' are here - for v3.2.13 - https://github.com/rails/rails/tree/v3.2.13/railties/lib/rails/generators/erb/scaffold/templates )

Railscast about Generators - http://railscasts.com/episodes/216-generators-in-rails-3?view=comments
(Watch from 8mins onwards for customizing info)

Other useful links related to Generators-
http://stackoverflow.com/questions/4333393/using-rails-generate-scaffold-when-model-already-exists?rq=1
http://stackoverflow.com/questions/4630911/override-default-scaffold-generator-in-rails-3
http://stackoverflow.com/questions/8688220/rails-3-1-changing-default-scaffold-views-and-template
http://guides.rubyonrails.org/generators.html

Rails - Javascript

From http://railsapps.github.io/rails-javascript-include-external.html

Rules of Thumb

In summary, here are rules of thumb to guide your use of JavaScript in Rails:
  • Logically organize your site-wide scripts in the app/assets/javascripts/ folder.
  • Copy external JavaScript libraries (such as jQuery plugins) to the vendor/assets/javascripts folder.
  • Let the Rails asset pipeline combine them all in one minimized application.js file.
  • List scripts in the app/assets/javascripts/application.js manifest.
In almost all applications, there is no need to add external JavaScript libraries directly in a view template. Use the Rails asset pipeline, even for JavaScript used on just one page (page-specific JavaScript). Copy external scripts to your application and you’ll gain the performance benefits of the Rails asset pipeline and avoid complexity.

Rails - to see all .js files that are being loaded

add the following to the URL -    ?debug_assets=1 

See Railscast on Assets Pipeline for more info - http://railscasts.com/episodes/279-understanding-the-asset-pipeline

Monday, July 8, 2013

Linux commands

Removing a directory that is not empty:
rm -Rf directory-name

Sublime Text:
http://www.dilipprajapati.com/2012/12/22/sublime-text-2-as-default-editor-in-ubuntu-12-04/

Rails, RVM:
https://rvm.io/integration/gnome-terminal
http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/
http://stackoverflow.com/questions/9056008/installed-ruby-1-9-3-with-rvm-but-command-line-doesnt-show-ruby-v/9056395#9056395

Is MongoDB running:
http://stackoverflow.com/questions/5091624/is-mongodb-running
check with either:
   ps -edaf | grep mongo   # "ps" flags may differ on your OS
or
   service mongodb status
Useful rvm commands to manage ruby versions using rvm:
http://stackoverflow.com/questions/8868555/how-do-i-uninstall-ruby-and-gems-using-rvm
Basically taken from http://beginrescueend.com/rvm/:
To list the available ruby versions to install type:
rvm list known
To then install from the list of known, type:
rvm install VERSION_NUMBER
To then use the ruby version you have installed:
rvm use VERSION_NUMBER
You can make a certain ruby version your default system version:
rvm use VERSION_NUMBER --default
To remove the ruby version, keeping the gemsets:
rvm uninstall VERSION_NUMBER
To remove ruby et al:
rvm remove VERSION_NUMBER
To learn about your ruby environment and where they are installed/aliased:
rvm info

Followers

Blog Archive