Thursday, January 30, 2014

Rails: specifying callback-javascript in response to Ajax request

respond_to do |format|  
  format.js { render js: "toastr.success('"+successmsg+"')"}
end

If callback-javascript is only 1 line of code or so, then we can avoid creating a new .js.erb file (with name of controller-action) and just include the javascript as above.

HipChat - Group Chat & IM for teams

https://www.hipchat.com/pricing - free for teams of size <= 5

Friday, January 24, 2014

Outside-In TDD

Boundaries of the System = User Interface OR Service Layer (like a Restful Service/Soap Service)

(Slide is from "Outside-In Test-Driven Development" course from Pluralsight)


Thursday, January 23, 2014

Ruby: eval, define_method, send

eval, define_method, send

http://rubymonk.com/learning/books/5-metaprogramming-ruby-ascent/chapters/24-eval/lessons/63-eval#solution3816
eval should best be avoided in real scenarios. Ruby has saner tools (#define_method#send) in its meta-programming repertoire that you can use to achieve eval-like cleverness.

Tuesday, January 21, 2014

Dependency Injection example

(I am trying to learn DI. Below is an Example from Adam Freeman's book - Pro ASP.Net MVC 5. Below is my attempt at understading the example in the book)
Dependency Injection example with Ninject: 

Starting point 

1. ShoppingCart's constructor expects a concrete class's object (i.e. object of class LinqValueCalculator)
2. HomeController's Index action is instantiating 2 objects before using them (observe the 'new' keyword being used in 2 lines of code)


Summary

In Stage1, we 'fix' ShoppingCart class (by transferring the responsibility of creating the object to HomeController class). 
Putting this in another way - we make it easier to write the ShoppingCart class, by asking HomeController to pass, as parameter to constructor, whatever ShoppingCart class needs 
Now we have to 'fix' HomeController class 

In Stage 2, we fix HomeController class

Stage 1 - left page in below screenshot

In page 124 (left page in below screenshot):

ShoppingCart has been 'fixed' now:
-- it has 'declared' that it has a dependency on an object of type IValueCalculator
-- It has done this 'declaration' via its constructor
-- basically it is saying - send me the object and I will use it; i am not going to go through the trouble of creating it
-- Also notice that, in ShoppingCart's constructor, concrete class LinqValueCalculator has been replaced by an interface IValueCalculator

- So, now the responsibility of getting hold of a IValueCalculator object has been transferred to Index() method of HomeControler.cs

Stage 2 - right page in below screenshot

In page 128 (right page in below screenshot):

Now, we use the same strategy with HomeController.cs :
-- we make it 'declare' that it has a dependency on an IValueCalculator object via its constructor
-- basically, now, it is also saying - send me the object and I will use it; i am not going to go through the trouble of creating it)

- So the question is - who is going to create the object now (since each class seems to be handing over that responsibility to someone else, and there is no one else to hand that responsibility over to) ?
Ninject or such DI container will do that...


Monday, January 20, 2014

Reverse Proxy

E.g. NGINX
http://en.kioskea.net/contents/308-proxy-and-reverse-proxy-servers
reverse-proxy is a "backwards" proxy-cache server; it's a proxy server that, rather than allowing internal users to access the Internet, lets Internet users indirectly access certain internal servers.
http://serverfault.com/questions/8654/what-is-a-reverse-proxy
A reverse proxy, also known as an "inbound" proxy is a server that receives requests from the Internet and forwards (proxies) them to a small set of servers, usually located on an internal network and not directly accessible from outside. It's "reverse", because a traditional ("outbound") proxy receives requests from a small set of clients on an internal network and forwards them to the Internet. 
http://www.jscape.com/blog/bid/87783/Forward-Proxy-vs-Reverse-Proxy
         has good diagrams to differentiate between a forward-proxy and a reverse-proxy

Wednesday, January 15, 2014

Cloud - Windows Azure



Below is a slide from "Windowz Azure Websites Deep Dive" course in Microsoft Virtual Academy

Observe how the 'bottom' layers go away, as we move from :
Your Datacenter => Azure Virtual Machines => Azure Cloud Services => Azure Websites
(Also observe how the image of the cloud gets bigger towards Azure Websites)
The layers that don't appear are the ones that Microsoft will manage for us (and we do not have control over)


Sunday, January 5, 2014

Rails: passing a variable to "render"

<%= render 'credit_card_info', :f => f %>

Then 'f' will be available as a local variable

http://stackoverflow.com/questions/4700617/pass-a-variable-into-a-partial-rails-3

Rails: to see path for a given named-route

In "rails console":

if login_path is a route-name, we can get the actual path via:

Rails.application.class.routes.url_helpers.login_path

Followers

Blog Archive