Thursday, February 27, 2014

Ruby: decorators, modules

Computer Programming in 5 minutes & Tiny-Robots

I have wondered several times how I would introduce 'programming' to someone who has never done it, not even a little bit.

Below is Larry Wall's take on it. He is the creator of Perl programming language.



The rest of this post is based on an idea from the above video - the idea of robots being at your disposal to do certain tasks.

We can probably explain programming-constructs, by :

  • asking the student to imagine that each programming-construct is actually a tiny-robot. So, for e.g., a for-loop, is actually a tiny-robot that is capable of just doing a 'loop'. Similarly, we can imagine a if-then-else tiny-robot, print-to-screen tiny-robot, etc
  • Notice that I modified 'robots' to 'tiny robots' so as to convey the idea/feeling that a tiny-robot can do a 'tiny' task
  • This idea might work because everyone knows that robots need to be instructed what to do i.e. robots need to be given 'commands'.
  • And it is also easy to add that the commands have to be very specific, otherwise the robot will not understand what to do. We would have introduced concept of 'syntax' by doing that.

And that is probably half the battle won right at the start.

------------------------------------------------------------------------
More complex point that can be introduced after a couple of programs -

  • We can ask the tiny-robots to give commands to each other. 

------------------------------------------------------------------------
Example:

PROBLEM:
Print numbers 1 to 100 on screen

TINY-ROBOTS AT YOUR DISPOSAL:
1. LOOP tiny-robot
2. PRINT-TO-SCREEN tiny-robot

Info about the LOOP tiny-robot -
obviously since it is a robot, we have to tell it exactly how many times it has to loop;
once we give tiny-robot this number, it stores it and starts looping; it keeps track of how many loops it has completed, how many are remaining, etc; the LOOP tiny-robot is quite smart in this aspect.

Info about PRINT-TO-SCREEN tiny-robot - 
this tiny-robot does nothing but print to screen whatever you give it.

SOLUTION:
Instructions from us (programmer) to the tiny-robots will be:
"LOOP tiny robot -  please loop 100 times"
"During each loop, since you keep track of how many loops you have already done, give that number to the PRINT-ON-SCREEN tiny-robot, and ask it to print that number on screen.
-------------------------------------------------------------------------------
(In the above example, I have tried to tackle the 'loop' construct, which is a slightly advanced concept for an absolute beginner.
Have to try and add IF-THEN-ELSE construct example;
If idea seems good, perhaps, I will try to create examples for all the main programming-constructs.
In the worst-case, it can be a good way for me to try out while trying to understand new concepts)

Wednesday, February 19, 2014

git add -p

http://johnkary.net/blog/git-add-p-the-most-powerful-git-feature-youre-not-using-yet/
If you use git, you've used the command git add. But do you know about git add's "patch mode" using git add -p ?
Patch mode allows you to stage parts of a changed file, instead of the entire file. This allows you to make concise, well-crafted commits that make for an easier to read history.

10-signs-that-you-are-an-awesome-web-developer

Friday, February 14, 2014

Tuesday, February 11, 2014

MySql: find out which tables contain a certain column

To search for a column 'rank' in a database 'mydb':

select * From INFORMATION_SCHEMA.COLUMNS Where column_name like '%rank%' and TABLE_SCHEMA = "mydb"

Monday, February 3, 2014

drive.draw.io - mockup tool

Ruby: yield

Ruby: inject

http://ruby-doc.org/core-2.0/Enumerable.html#method-i-inject

inject( initial )  { |memo, obj|      block  }  → obj

def sum_of_cubes(a, b)
  sum = 0
  (a..b).inject(sum) { |sum, x| sum + (x*x*x) }
end

What does it do ?
-- Combines all elements of enum
-- by applying a binary operation, specified by a block

For each element in enum -
- the block is passed an accumulator value (memo) and the element
- the result becomes the new value for memo.
At the end of the iteration -
the final value of memo is the return value for the method.

Variation:
-------------------------
inject  { |memo, obj|     block  }  → obj

What is the initial value for memo ?
- If you do not explicitly specify an initial value for memo, then the first element of collection is used as the initial value of memo.


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

Tuesday, December 24, 2013

Ruby: split vs regex, Benchmark

http://stackoverflow.com/questions/7533479/ruby-string-search-which-is-faster-split-or-regex

require 'benchmark'
Benchmark.bm do |x|
    x.report { 50000.times { a = 'a@b.c'.split('@')[0] } }
    x.report { 50000.times { a = 'a@b.c'[/[^@]+/] } }
end

Sunday, December 22, 2013

Rails: routes

If we want to 'namespace' our routes, but do not want the 'named routes' to have namespace's name in the prefix:


namespace :admin, as: '' do
   get '/post/new' => 'posts#new', as: 'new_admin_post'
end

To learn Orchard CMS

Monday, December 9, 2013

Ruby: each_with_index


X.each_with_index do |item, index|
  puts "current_index: #{index}
end

Monday, December 2, 2013

Rails: Reordering Columns

Sometimes it is necessary to reorder columns so that data is presented, by default, in a more meaningful way e.g. the 'key' columns probably should appear in the beginning, followed by other columns that do not allow a Null value, followed by columns that can take in Null values (basically, are not that important)

http://stackoverflow.com/questions/18899011/rails-4-migration-how-to-reorder-columns

Sunday, December 1, 2013

Rails: scope in models

scope :my_books, lambda {|user_id| {:conditions => ["user_id = ?", user_id] }}

Have to read about scope and conditions - how to specify And , Or ?

Wednesday, November 27, 2013

Google: Small Teams

http://davideckoff.com/2008/09/google-at-10-interview-with-marissa-mayer-small-teams-and-leapfrogging-part-4.html

When I joined Google, there were 9 engineers and we organized in 3 teams of 3. And we knew we were going to add 9 engineers by year end, so there’d be 18 of us. And Larry and Sergey said, “You know what? By year end, we don’t want to have 3 teams of 6, we want to have 6 teams of 3. Let’s keep the core team at the size 3. Because if we have twice as many engineers, we don’t want to be doing all the same things twice as well, we want to be doing twice as many things.”

iDoneThis, Buffer

iDoneThis.com - share & store info about work being done
bufferapp.com - scheduled posts to Social Media websites like Facebook, Twitter

iDoneThis 'dones' from command line - https://github.com/influitive/idonethis

Teams can even integrate with Github so that commits can be added to 'dones'.

Monday, November 25, 2013

Free Online Courses for ASP.Net MVC

To learn MVC, it looks like there are 2 main options for videos -
1. http://www.microsoftvirtualacademy.com/
2. Pluralsight videos - http://www.asp.net/mvc/videos - This has Pluralsight's videos (for MVC4, MVC 3, MVC 2 ).

Saturday, November 23, 2013

Rails on Windows Azure

Suggestions for Meetings

http://www.linkedin.com/today/post/article/20130819190438-36052017-cut-your-meeting-time-by-90

Storing some points from Comments here:

...I can attest to the importance of meeting to delve deep, hear disparate views, observe and be influenced by others - this is a social process. To think you can do that in one meeting only prior to deciding a key strategic direction is dangerous...

Meetings need to be clearly managed, for, where the group is in a complex-decision-cycle. And when it's time to decide, and the rigor and conversation has been there, then decide and move quickly.

I believe the best decisions come from collaboration. My experience has been that only happens when people are encouraged to participate in the process. This takes time.

over the years I’ve learned to appreciate that, sometimes, we need to attend meetings where nothing gets decided. Sometimes meeting just for deciding and committing makes you blind and deaf to what is really going on in your company and this can lead to disaster later on. So make sure you spend at least 10% of your time, doing unproductive meetings, just to make sure you know where you stand in the big picture.

I have great experiences when thinking alone over alternatives does not give full range of options, while having "group thinking" you can come up with some brilliant ideas which one would never think off alone (simply because of limited knowledge and lack of experience). The key thing in such cases is that people have to come prepared with some initial thoughts.

there are three functional purposes for having a business meeting: 
To inform and bring people up to speed 
To seek input from people 
To ask for approval 

 The general relationships meeting is almost the most important of the lot; Repeat after me: relationships lead to results

Bozhidar Ivanov
I believe that if, for example, you would like to enforce teamwork, tolerance towards different opinions, calibration between your teammembers and, last but not least, educate and develop your team, the time spent on meetings is not wasted.
I am far from believing that the time I spent with my team, even on 1 on 1 meetings, should be considered as a "loss"

Liran Tal
there are some introverts amongst us. We really like to listen

Mike Manley
Unfortunately sometimes the only way to get some people to focus on something that requires their contribution is to pin them down to a meeting. Otherwise it sits at the bottom of their list and you spend far too much time chasing.

David Pointon
 there are 4 types of meetings, 1. Decide, 2. Consult/Collaborate, 3. Inform, and 4. Relate

The point is to be clear on the core purpose of each meeting. 

 As an example, It is perfectly OK to have a productive, well structured Consult/ Collaborate meeting if people are aware of when and how their inputs will be converted into Decisions. Indeed, as more staff and stakeholders actively seek engagement, this is a crucial step in moving towards Decisions.

In a Decide-only meetings culture, much of the opportunity to engage would be pushed underground, leaving people unclear about when and how they can get involved.

Robin Merritt
Some meeting concepts I have learned over time that has helped me:Have an agenda but share it before the meeting (seems simple but it doesn't always happen), include others in the meetings, when you can, to "own" a topic, try standing in a meeting - they go by faster!, don't invite the entire team to every meeting but just the ones that can decide and commit, and some meetings are just for morale and relationship building so chose the attendees wisely because not everyone wants to join those meetings at work.

Ingo Susing
sometimes meetings have the (implied) objective of creating social capital and strengthening relationships, arguably a critical ingredient to create an environment of trust which is fundamental to effective teams

Sarah Greene
In the knowledge economy, sharing what you know as a subject matter expert is considered currency, and a form of power. So to some extent this model requires people to cede some of their personal power for the good of the whole.

Ragavan Dhandapany
One more thing which i find useful is to have 'your own agenda' before participating in the meeting. Before you start wondering about 'personal agendas' what I really mean, is to go through some meeting materials before hand and list down those things that you definitely want to express or discuss. Often, people just walk into a meeting room, just because it is in their calendar...

Pat Elliott
there will always be a need to have "Update", "Inform" and "Educate" meetings to ensure progress on initiatives are shared with everyone, to inform employees of major business decisions/actions/strategies and to educate individuals on many topics.

Roy W. Haas, Ph.D.
I was once on a large project that was reorganized because of time and cost over-runs. The new project manager had a status meeting every morning at 8am. If you were there at 8:01, you didn't get any donuts, no matter your management rank. The only things we did were "decide" and "commit" by going around the room. The project got back on track quickly and was a success.


Dmitry Belenko
This only works if you don't ever need to figure out HOW to do something, or WHAT to build, or ask for an expert opinion, or give expert opinion, etc. In other words, this doesn't work for anything creative, because without constant communication with the rest of the team you will simply build something far removed from what people actually want. As much as I dislike "communication overhead", there's a lot of value in it. 

The right way to tackle the communication overhead is how Google tackles it: keep the team sizes small.

Carl Thompson
We have a motto "if you can't handle it in three emails, meet on it".

Ashraf Saeed
“Why do we need to meet to accomplish this?” This question make sense to me

Michael M. Obradovitch II, Esq., REA
Another quick "acid" test of how well your meeting is progressing: Make a mental note of the number of Questions to the number of Answers and Reactions. If there are too many questions: People are generally unprepared for the meeting and you're wasting valuable time - cut meeting short and have people "retool". If there are too many Answers and Reactions: Emotions are taking over better adjourn. If the ratio of Questions to Answers and Reactions is close to 1:1 the group is working through the issues and the agenda -- let it ride.

Barbara Lennartz
Another issue for me is: Come to the meeting prepared. How can things be decided if the person who needs the decision and wants the decision comes with little preparation. That's what often makes the meeting end in discussions and postponing decisions.

Murray Lynn
But I have also seen them get to the point in their meetings where they decide and commit without being able to execute effectively.Part of having everyone on the same page is having everyone know they role and how their role compliments and impacts other roles on the team. 

This does not require a long drawn out discussion. It can be a simple as a football huddle, quick and to the point. This little step before execution can make a world of difference.

John Koudela III
I suggest that the supposed content of the meeting be documented, shared for comments, agenda made, prep sheets sent out with rules of engagement

And then at the meeting have each person acknowledge they are prepared for the meeting. If they haven't or just got to the materials a little before - they can leave. Only those prepared for the meeting should attend. Every meeting should have a facilitator. The meeting should have a time limit. One person should take down key points of the meeting and later distribute them so members of the meeting can add it to their own notes.

Followers

Blog Archive