Around one year ago, I had started experimenting with concepts of creating programming languages. I first started with building few DSLs (Domain Specific Languages) using Ruby and Boo. It was quite interesting to work on development of DSLs. While doing this, I learnt a lot about how the programming languages are developed.
Eventually, I thought of writing my own programming language. While I was in engineering college as a student, we had a subject on language translators. This subject taught us lot of theory on how languages are compiled or interpreted. However, we never got a chance to write even a simple programming language during our practicals. According to few, it was not possible to write one in one semester’s time.
That turned out to be my main motivation. I decided to write this programming language without using any compiler tools like LEX and YACC. I ended up writing my own lexical analyzer, the grammar parser and the language using the concepts taught to us in engineering college only. I worked on it daily for around an hour and within two weeks, I had the basic language ready.
Yesterday I was reading an article on “How to Uninstall Symantec AntiVirus”. The article was from EzineArticles. While reading it, I suddenly noticed that the AdSense block is showing a complete unrelated ad on the page. Take a look at the screen-shot below.
For those who don’t know, Deepika Padukone is a bollywood actress. The article I was reading was related to removing a software (Symantec Antivirus) which was not related to film industry or actors in any context.
I found this quite funny and thought of sharing it. Do you find it interesting as well? Let me know your thoughts through comments.
In Ruby on rails, methods that generate urls from named routes are not globally accessible. For example, you can’t access them from console (script/console). If you want to use these methods from such places, then the rails documentation for ActionController::UrlWriter suggests two ways of doing it. According to this documentation, you can:
Include ActionController::UrlWriter in your class
Call the method directly on ActionController::UrlWriter
When I tried it out, only the first method worked. I was able to use methods generated from named routes in console after including ActionController::UrlWriter. However, it was not possible to call those methods on ActionController::UrlWriter. This looks like an issue with documentation to me.
It might be the case that the second method used to work in earlier version of rails. As rails is constantly being developed, some refactoring might have made the second method obsolete. I hope rails community will fix such issues in documentation soon.
While testing methods that return boolean values in ruby (the ones that end in ‘?’), try to avoid following matchers:
method_returning_true?.should be_true
or
method_returning_false?should be_false
This is because, ‘be_true’ and ‘be_false’ matchers considers ‘nil’ to be false and anything other than ‘nil’ to be true. When we write methods in ruby which end with question mark (‘?’), intent is that the method will return boolean value. To ensure that our tests will always reflect the intent of code, use following to assert boolean values instead of using ‘be_true’ or ‘be_false’ matchers:
Few days ago I came across a story here. In this story, an assembly line worker suggests a simple, low-cost but highly effective solution to the problem for which engineers had developed a complex and expensive solution. Why am I referring to this story today? Because, I notice lot of people having a misconception that you need to have a complex system to solve a complex problem.
People innovate and develop solutions or machines to reduce human efforts. In other words, machines or solutions are developed to simply our day-to-day activities. By developing complex systems, most of us don’t realize that:
Instead of simplifying something, we have actually transferred the problem to another new system: Complex solutions give us an impression that it solves the problem completely. But in reality, it might end up creating new problems for you. This new problem could be in the form of maintenance or in the form of some hidden cost.
Complex solutions are often too costly: This means that only few rich people will be able to use the solution.
I am sure that most of us would have heard about interactive whiteboards (also known as smart boards). These boards are quite costly as they would cost you at least few hundred thousand rupees. Due to this high cost, lot of schools and colleges cannot enjoy the benefits of such iterative systems. Now, is there a cheaper and simpler solution to this problem?
Of course there is!!! Johnny Chung Lee, who works as a researcher at Microsoft – Applied sciences, has developed a simple systems that achieves most of the functionality provided by commercial smart boards at fraction of their cost. His project makes use of an IR pen, Nintendo Wii remote and a small software application. You can watch the following video to know how this system works:
Next time, before developing any solutions or systems, try to ask yourself a question: “Is this the only way of doing this? Can there be simple way to do it?”
Today I came across an online tool that allows you to see the screenshot of pages in the google search result. You can give it a try at “Veesual.com”
While I found the concept to be interesting, I was wondering what could be the use of looking at screenshots of pages in search result. What matters to me is getting a list of relevant search results. A thumbnail of a particular page in search result won’t help me in determining how relevant that page is to my search.
However, I do see one use for getting search results along with thumbnails. It can be used to come up with ideas for designing web-sites for a particular theme. You can search on Veesual using a keyword that describes the theme of your site and then take a quick look at the design of pages in the result. This can help you to come up with your own web-page design.
Do let me know if you can think of some more applications of Veesual.com
public class Person
{
private string name;
private int age;
public string Name{
get {return name;}
set { name = value; }
}
public int Age{
get {return age;}
set { age = value; }
}
}
If I want to set the value of Name and Age property on the instance of Person class, I’ll need to refer to that instance for every property I need to set in the code. For example:
var person = new Person();
person.Name = "Super Man";
person.Age = 30;
It would have been great if C# had an equivalent of VB’s “With..End” statement, where we could refer to the instance of Person class only once and then refer to properties only.
Today, I came across this post “mucking about with hashes…“, which shows how C# lambdas could be used as hashes. Using this concept, I implemented a simple extension method that simulates the behavior of VB’s “With..End” statement to some extent.
Here is the code for extension method:
public static class MetaExtensions
{
public static void Set(this object obj,params Func<string,object>[] hash){
foreach(Func<string,object> member in hash){
var propertyName = member.Method.GetParameters()[0].Name;
var propertyValue = member(string.Empty);
obj.GetType()
.GetProperty(propertyName)
.SetValue(obj,propertyValue,null);
};
}
}
Using this extension method, we can set the value of properties on instance of Person class as follows:
var person = new Person();
person.Set(
Name => "Super Man",
Age => 30
);
Yesterday I installed and activated Blass2 theme for this blog. I liked this theme as it was very simple and free from any extra graphics. After installing the theme, I discovered that “SyntaxHighlighter Evolved” plugin which I use to display code segments, was not working. I searched for other themes which are similar to blass2 and can run syntaxhighlighter plugin, but couldn’t find anything better. Finally, this is how I fixed it.
To fix it, I had to edit ‘footer.php’ of Blass2 theme using inbuilt theme editor of WordPress (Appearance > Editor). The original ‘footer.php’ looked like this:
If we want to share a file or photos while chatting with our friends on internet using IM tools like GTalk, we use file sharing services available online. These services allow us to upload a file to their servers and give us a link which we can share with our friends. But what if you are a developer and want to share a small piece of code with your friend? You are left with following choices:
Paste it in your chat: I know most of us do this when we quickly want to share the code. However, its annoying as it becomes unreadable and makes your code look as if its obfuscated
Email: This approach is better compared to previous approach, however the recipient wil need to manually compile the code and run it if he wants to know the output.
I won’t say these approaches are useless. But I would like to have a place, where I can put my code fragment and then share it using a link. I can use this link in my gtalk status, chat or even in twitter posts.
Luckily, there is a site called “codepad” that allows us to do exactly the same thing. It allows us to share a piece of code using a small url.
Today, I managed to install Mono 2.4 in Ubuntu 9.04 without affecting Ubuntu’s default mono installation. Thanks to the instructions here (Building Mono 2.4 from source on Ubuntu 8.10), I was able to install latest mono/monodevelop in a parallel environment. Now I can work on C# 3.5 code in Linux as well.
Here is the screen shot of MonoDevelop instance with the code given in this post.