Skip to content

Instantly share code, notes, and snippets.

View ParthBarot-BoTreeConsulting's full-sized avatar

Parth Barot ParthBarot-BoTreeConsulting

View GitHub Profile
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / overlay-code-fragments
Created October 4, 2013 12:08
Design an UI-Overlay for the webpage using jQuery
// JS CODE ===================================
//Added for overlay, while ajax data is being loaded.
var $overlay_wrapper;
var $overlay_panel;
function show_overlay() {
if ( !$overlay_wrapper) append_overlay();
if(!$($overlay_wrapper).is(':visible'))
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / js_patterns_articles
Created October 17, 2014 14:24
Useful Javascript articles - JS patterns
http://blog.jerodsanto.net/2012/02/a-simple-pattern-to-namespace-and-selectively-execute-certain-bits-of-javascript-depending-on-which-rails-controller-and-action-are-active/
http://css-tricks.com/how-do-you-structure-javascript-the-module-pattern-edition/
Super - http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript
http://rmurphey.com/blog/2009/10/15/using-objects-to-organize-your-code/
http://alistapart.com/article/the-design-of-code-organizing-javascript
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / Converted JS class code
Last active August 29, 2015 14:07
Create Javascript class using coffe script
var TemperaturesController;
if (this.Elijah == null) {
this.Elijah = {};
}
TemperaturesController = (function() {
function TemperaturesController(opts) {
this.opts = opts;
console.log("temps init!");
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / nested_coffee_script_classes.rb
Last active August 29, 2015 14:07
Nested class structure using coffee script
class UsersProfileController
constructor: ->
return
assets: (params) ->
@a = new AssetsHandler(params)
@a.one()
@a.two()
return
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / baruco.org -notes
Created October 29, 2014 06:17
Fast Ruby - Barcelona ruby conference video notes
=================================
def slow(&block)
block.call
end
def slow
Proc.new.call
end
- The below one is 5 times faster then above, in execution
def users
per_page = Variable::default_pagination_value
@users = User.find(:all)
# First, check to see if there
# was an operation performed
if not params[:operation].nil? then
if (params[:operation] == "reset_password") then
user = User.find(params[:id])
user.generate_password_reset_access_key
user.password_confirmation = user.password

Ruby Notes - 1

  • Use is_a?, kind_of?, instance_of? method to check type of any variable

  • Explain the usage of method in detail, as a comments before method

  • Use compact method to remove nil from arrays

  • Use tap method as follows, avoid writing an extra line to return object Instead of,

    def update_params(params)

params[:foo] = 'bar'

@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / README.md
Last active October 13, 2015 18:17
How to write tests?
  1. Identify what are diff. use cases we need to test, and define 'test' method for each. For the above example, we need,
  • breaking_fact
    • test for 0
    • test for 1
    • test for any other number (say 3)
    • test for big number, which should break and throw exception.
  • fact
    • test for 0
    • test for 1
  • test for any other number
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / READ_ME.md
Last active October 13, 2015 19:38
Rails Cheatsheet - basic rules to remember and use in every code you write

Some basic rules to follow, for diff. rails components. Please add comment if you want to add anything.

##Controllers

  1. Extract common code in controller action, which loads data from DB using finder methods with params as arguments.
  2. Same for any service object loading.
  3. Above two cases, if being used in more than one controller, then define a concern using included do before_action :finder_method end and include that in both.
  4. Do not write separate controller for API, instead use respond_to with diff. data format.

##Basic Rules of estimation

  • There are no fixed set of rules for estimation, but still there can be some based on what we have experienced so far in "Agile" projects. The so called "Waterfall" project execution model is obsolet and rarely used because now the products are constantly evolving and features are removed/added very quickly based on business dicisions ( :'( We all hate this! But its truth! )

  • Understand the requirements first, in detail

  • You should avoid estimating what you can count. And if you can't get a count, you should at least try to compute the estimate from a related count.

  • Identify use cases and clarify each and every step for them. This will give more insights about the requirements, and clarifies whole flow.

  • Like, What user will do here, when he clicks what happens, when he enters wrong/no data, what if file is bigger