I'm a hacker and an early stage investor interested in solving common problems in the simplest way possible.
I'm also the creator of Sociaholic.com - A better way to post tweets to your facebook
Search
Simplest way to assign attribute values from constructor (initializer)
Ever wondered how you can assign attribute values for a ruby class directly from initializer with less code? check out the gist below.
Interview with Ideatin.com on Sociaholic
my recent interview with Ideatin.com on sociaholic.
It ain't about the capital. Its about iterating and learning with speed.
Yesterday's standoff between Fred Wilson and Ben Horowitz and the rant about finance made me realize there is lot of confusion about the Lean Startup up model.
If a hack like me can get it, makes me wonder what is so complex to understand in the Lean Startup model, so I decided to clarify what I felt were few misunderstandings:
Its NOT about begin cheap, its about iterating and learning. Lean startup emphasizes on continuous learning during the product development life-cycle, not about technology but about your CUSTOMERS and their needs and making some thing they want to buy.
Minimum Viable Product (MVP) is NOT a buggier and cheaper version of your final product, but has just those features that allows the product to be deployed which will result in determination of the product/market fit. Simple terms, it lets you find out if you are building some thing people want. Venture Hack's has few great examples of MVPs and Eric Ries has an awesome guide that will help you get started.
There are other ways to achieve product/market fit. Dropbox did it by posting a video of the product even before it was complete.
The argument about Lean startup principles apply only to Web Startups is completely utterly WRONG. If you are creating a cure for AIDS, common sense tells us that you have market for it and all you need is the product. YOU HAVE ACHIEVED PRODUCT/MARKET FIT.
About finance - IT DOES NOT matter how much capital you've raised. YOU WILL FAIL if you don't have the product/market fit... Even TESLA MOTORS can flop if no one wants to buy their cars.. its really that simple.
The Lean Startup method is not about cost, it is about speed. Lean Startups waste less money, because they use a disciplined approach to testing new products and ideas Lean Startup model is a framework that helps you determine product/market - Eric Ries on Four Myths about Lean startup
Powerful Twitter API Wrapper in less than 50 lines using Ruby Metaprogramming
I've been long fascinated about active record dynamic finders (find_by_) and wanted to write some thing similarly elegant, this twitter client uses ruby metaprogramming to dynamically generate objects and methods and adds simpler and easy to user methods for Twitter REST API
For. e.g., the REST method 'user/show' at http://api.twitter.com/1/users/lookup.json can be invoked simply by calling Twitter.new("user","pass").user.show(:screen_name => "gregosuri")
Some explanation of the code:
The program is constructed very similarly to active record dynamic finders, at the core it overrides object's method_missing and dynamically constructs the missing methods, Jay Fields has an excellent blog post that explains this technique.
For e.g., in client.statuses.show(:id=>'1234') the client object (Twitter instance) does not have statuses object during initialization, when this is called, it invokes the method_missing of Twitter class, and since this method(statuses) does not have any arguments or ends with post/get, method_missing will return 'self', i.e., in our case the statuses object. The Proxy is used to buffer the methods, this is useful to construct the URL for later use.
Now, 'show' method is called on 'statuses', since this has arguments it get processed by doing a HTTP GET to Twitter API. Once we have response from the server, an instance of TwitterResponse is created, the construct method accepts a hash/array and converts them into attributes and methods by using object.instance_variable_set and object.send in the constructor
Hope this helps, please follow me on twitter and/or subscribe to this blog.
New Product Failure Rate: 3000 Ideas = 1 Success
I created this info graphic for a friend, some hard facts:
- 1 of 3 launched products fail despite research and planning
- 1 out of 4 projects that enter development make it to the market
- 46% of all resources allocated to new products by U.S firms is spent on failed products
If you like this, please follow me on twitter.com/gregosuri or subscribe to this posterous.
On "Scala Vs Clojure", What the market thinks.
I was researching on ideal Functional Programming for the Java Platform and narrowed the search to "Clojure" or "Scala". There has been lots of discussion on the topic as to which will be the next big thing (essential replace java), I decided not to go into comparison war here, but recommend Clojure vs Scala in you are interested.
Both are amazing languages, being from the Ruby background, I'm a bit biased towards Clojure but decided to some research on what the talent market's reactions are.
On an Absolute scale, Scala seem to out trend Clojure. Below is the chart to support that claim and also a Simply Hire search returned about 255 new Jobs.
But then on an Relative Scale, Clojure has shown remarkable growth. Even though the Simply Hired search returned around 107 Jobs, 8000% percent growth in less than an year is hard to ignore.
Conclusions. I've decided to go with Clojure cause the syntax proved to be much cleaner and of course has much tighter integration with Java. STM implementation is also genius in Clojure. Bottom line, the decision is yours make and really depends on your preference.
Sort on any attribute for objects stored in an array using Ruby Metaprogramming
Update 1: You could use array.sort_by{|obj| block } to achieve the same functionality. Read further if you are interested in learning more about Metaprogramming. (Thanks to knowtheory)
Ruby Metaprogramming is incredibly powerful, there are lots of good material and books but most of them i came across lack practical examples. One problem I was trying to solve is to perform a Bubble sort on objects stored in Array on their attributes, I believe this is a very common problem and I was able to do it with ease using almighty META.
I strongly advise watching the video by Dave Thomas and understand Ruby Object model before reading further.
The Problem
I have 6 objects of Person type in an sporadically created Array, each of them have 2 attributes - Name and Line_no. We want to sort the array based on Person's line number.
Solution
We decided to use Bubble sort, mainly because its a simple to understand and we want any object to be able to use this function with out much modification. For simplicity purposes, I'm sorting ascending only on Integers, also assuming all the objects in the array are of same type.
First thing, is extending the Array to house our method "sort_by_attrib!"
class Array def sort_by_attrib!(attrib) .... end end
If you notice closely in the code below, the ruby "self" is used at multiple instances, while self can change depending on where its called. It always represents the current/default object.
Also notice the send method which lets you call a method on the object. In our case self[i].send("#{attrib}") will return the value of the instance variable name that has the value of attrib, in our case it returns "line_no". The rest is pretty much the logic to do a bubble sort.
Full Code:
Hope you enjoyed the article, I greatly appreciate your feedback and thought. Please subscribe and follow me on twitter for more incredible updates.
Connecting to IBM DB2 (on a mainframe) using JRuby and Active Record (If you care)
I'm going to cut the bull crap about why JRuby is awesome and get to the point, I was trying to access an old IBM Mainframe for a batch program in JRuby and couldn't find any thing useful on the blogosphere, so I decided to share how I did it. It was pretty simple using the Active Record JDCB adapter
Setup:
- Mac OS 10.5
- jruby 1.4.0
- ruby 1.8.6
- activerecord (2.3.5) - gem
- activerecord-jdbc-adapter (0.9.4, 0.9.1) - gem
- rails (2.3.5) - gem
Step 1: Install and setup JRuby
Step 2: Install the necessary gems (rails and activerecord)
jruby -S gem install rails activerecord-jdbc-adapter
If you choose to avoid rails, you can install active record as standalone too.
Step 3: Install Drivers
Download the DB2 Type 4 JDBC Drivers and place them in the same directory as your program, you can find them in your DB2 installation. You will need the following:
- db2jcc-9.1.jar
- db2jcc_license_cisuz-1.0.0.jar
That's pretty much it, check out the code sample to get you started
Code:





0 Comments