tag:blogger.com,1999:blog-73612312163880385092024-03-13T04:50:08.798-07:00The Pie, The Only Programmer With A LifeJust my random thoughts about Technology and Africa.Unknownnoreply@blogger.comBlogger15125tag:blogger.com,1999:blog-7361231216388038509.post-85495255517016335942015-01-08T09:04:00.001-08:002015-01-08T09:04:03.549-08:00AppBrains-Android Monks : Understanding The Path Environment Variable<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/Xb23DbIXYJg" width="420"></iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-54400996624033612982015-01-08T09:00:00.000-08:002015-01-08T09:00:55.113-08:00AppBrains-Android Monks : Setting The Stage<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/jbIVF0sNe1w" width="420"></iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-52463703235011340052015-01-08T08:57:00.001-08:002015-01-08T08:57:07.606-08:00AppBrains-Android Monks : Objectives & Prerequisites<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/EBXy-25jINo?list=PL5MBdY0Scom1FX7dF_3uv-KTN2QjF_xZO" width="560"></iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-46883025717786974812015-01-08T08:55:00.001-08:002015-01-08T08:55:42.238-08:00AppBrains-Android Monks : Introduction<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/4sPcXgDa00s?list=PL5MBdY0Scom1FX7dF_3uv-KTN2QjF_xZO" width="560"></iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-5293458298261635402015-01-08T08:52:00.000-08:002015-01-08T08:52:20.879-08:00AppBrains-Android Monks : Welcome<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/DzhhZDVbsJ4" width="420"></iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-58828774654898353672014-08-05T02:30:00.000-07:002014-08-05T02:30:57.448-07:00Learn A Pattern A Week With Pie - Builder PatternWelcome back to our series on design patterns.<br />
<br />
This week our focus will be on the <b>Builder pattern</b>, a creational pattern which provides ways to construct a complex object one step at a time.<br />
<br />
So let's say you've a class called Student with a constructor which accepts 3 parameters; firstname, lastname and department. Obviously, creating an object of our hypothetical Student class is a no brainer. Just pull out your editor and fondle some few keys to get it done as shown below:<br />
<br />
<b>Student s = new Student("Edward","Pie","Computer Science");</b><br />
<br />
The above snippet is easy enough to be memorised by a day old chick, isn't it?<br />
<br />
What if you'd a constructor which accepts 10,15,20, or more parameters? Would you still go by the strategy above? Yes or No? Be honest!<br />
<br />
Wait babe, don't flush in 10,15,20 or more arguments into your constructor. That's gluttony and you know that's unprofessional. And now you're wondering, "what else can I do?" Uuhhhhm! Ok lemme create a parameterless constructor and throw in a bunch of setter methods to set properties on the object.<br />
Really? Mr. holy sinner, there's a better way (ask your parents).<br />
<br />
Aaaah! I caught you there, now you're scratching your head and you're saying "what the heck am I to do?" Tadaaaaah! The Builder Pattern says, "hey! I am every heck you've to do"<br />
<br />
<b><u>The Builder Pattern</u></b><br />
<br />
This is a pattern for constructing complex objects in a step-by-step approach using simple objects. In this pattern, a Builder class which is independent of other objects builds the final object in succession of steps.<br />
This pattern falls under the creational pattern in the GoF's grouping of design patterns.<br />
<br />
<b><u>Ti's Time For Hands-On</u></b><br />
<b><u><br /></u></b>
Let's have a practice lab session and try out one of the simple ways of implementing the builder pattern.<br />
We'll continue working with our hypothetical Student class, this time it accepts 6 parameters instead of 3. Six parameters aren't too much to be supplied as arguments to a constructor but we're sticking to 6 parameters just so it'll be easier to understand. You'll be able implement a Builder for a much complex object after understanding this.<br />
<br />
The 6 parameters for our hypothetical Student class are firstname,lastname,department,cwa,level, and hallOfResidence.<br />
<br />
See a simple implementation of the above scenario below:<br />
<br />
<script src="https://gist.github.com/hackstock/f4d0bde7a55100eb383b.js"></script>
<br />
<br />
I admit you've to add extra code to implement the builder pattern for such a simple scenario but the focus is on being able to construct complex objects in a step-by-step approach. With the builder pattern, you're able to chain a series of setter methods calls with each call taking the object under construction a step further.<br />
<br />
Consider a typical real world situation where you take your car to the car repairs shop, the fixing of your car's problems may start with the welder welding broken pieces together, the auto-electrician fixing electrical problems, the mechanic fixing your engine and finally the sprayer giving your car a new look. You'll agree with me that the movement of your car from one expert to the other takes it closer to your final goal, fixing your car. This is how the builder pattern works. It helps you to construct complex objects in a step-by-step manner.<br />
<br />
There are other ways of implementing a builder but for the sake of understanding I chose a very simple approach.<br />
<br />
Your comments, suggestions, questions and criticisms are welcomed here or on Facebook.<br />
<br />
Thanks for learning with me. See you in the next post!<br />
<br />
Remember to have fun!!!<br />
<b><u><br /></u></b>
<b><u><br /></u></b>
<br />
<br />Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-7361231216388038509.post-30347792034642896442014-08-03T15:47:00.001-07:002014-08-03T15:47:25.522-07:00My Highly Opinionated Thoughts On Learning ProgrammingThis is gonna be a rather long and highly opinionated post on mastering programming so I advice you grab a cup of coffee and sip slowly as you read with an open mind. Like I said, the points aren't laboratory certified ways of mastering programming 1, because I'm not a master programmer yet (at least per the people I keep as mentors) and 2, because what worked for me may not work for you. Pass what you read here through your own filters, assimilate what resonates with your style and shove the remaining shit out of your brain.<br />
<br />
<b><u>Choosing A Programming Language</u></b><br />
<b><u><br /></u></b>
I'll urge you to love to be a polyglot (be able to program in multiple programming languages). Choose at least 1 mainstream programming language eg. Java or C# .NET or PHP and some other non-mainstream programming language eg Python, Ruby, R etc. Your location determines what's mainstream and non-mainstream. In Ghana, Java & C# are mainstream. Also, master different languages for the different paradigms especially OOP and functional programming. If the only tool you've is a hammer, every problem appears to you as a nail. It easier to find a not-so-well-paying job with your skills in the mainstream. Conversely, it's difficult to find a job with your skills in the non-mainstream but remember to say thanks to Pie when you hit that high paying job which needs your skills badly.<br />
<br />
<b><u>Master Syntax & Semantics</u></b><br />
<b><u><br /></u></b>
The best way to learn any programming language is to master the syntax and semantics of the language. Don't sit all night cramming crap you don't understand into your head. Until you learn to understand, you can't really build good stuff with your language of choice. Don't rush it. You aren't in any race. Slow it down, learn it well, understand it and use it well. Learn to share your knowledge freely once acquired. Don't fool yourself by thinking it's an advantage if only you can do it. You know why? Simply, you don't know shit. People know more than you do yet they are humble and love to share. The more you teach, the more you understand.<br />
<br />
<b><u>Learn & Apply Design Patterns</u></b><br />
<b><u><br /></u></b>
You don't know of design patterns? Meeehn, you're so not current. A simple Google search will land you on some awesome sites where you can learn and apply design patterns. It will help you avoid writing spaghetti codes and also shun voodoo programming. Don't spend hours wondering how to write some piece of code. Some older dude faced similar issues, fixed and documented the procedure just to make life easier for your lazy ass. Sorry, you ain't lazy, you wouldn't have read this far. lol!<br />
<br />
<b><u>Read & Write Lots of Codes</u></b><br />
<b><u><br /></u></b>
Until you read code written by others you may think you're the best programmer ever created. Code writing is easy, code reading isn't. Every developer thinks the other guy who wrote the code he's been called to maintain is an idiot. Why? Simply because you've bad code reading habit or maybe the guy was indeed an idiot, a typical text book example of an idiot. The pun and jokes not withstanding, take these points serious. You learnt how to write code, you've to learn how to read code as well. Join some open source projects, get insulted and intimidated by the experienced dudes. They won't forgive you for posting stupid code, you'll get hurt but you'll dare not repeat yourself.<br />
<br />
<b><u>Invest In Your Skillset & Toolset</u></b><br />
<b><u><br /></u></b>
Make learning a life-long process. Buy books if you've the means, watch video tutorials. Never enter tomorrow being the same person you are today. Wake up every morning knowing you're a better person. Buy good computers. Use your snail-paced PC for a doormat. Save and buy some fast computer, at least fast enough to launch your IDE before you blink 10 times. Know what you don't know and never be satisfied with what you know. If you don't know, and you don't know that you don't know then you're a fool.<br />
<br />
<b><u>Have A Mentor, Be A Mentor, Change Mentors & Don't Be Changed As A Mentor</u></b><br />
<b><u><br /></u></b>
<b><u>Have A Mentor</u></b><br />
Whether you like it or not, you aren't the best programmer. Every other programmer, even the greenhorns know something about programming that you don't know. That you've programmed for 20 years doesn't make you the best programmer around. Stop crowning yourself in your utopian world. Shove your pride up your ass, step down, get someone who's better than you, humble yourself and learn from this guy. Choose a mentor and learn from him.<br />
<b><u>Be A Mentor</u></b><br />
The best way to learn is to teach. You'll hardly forget what you've taught over and over. Don't be stingy with your knowledge. The truth is, you don't know jack. Others know more than you do yet they freely share. If someone sat on this knowledge you wouldn't get to know of it. Count the number of books around you, the number of videos freely available, the write-ups, the blog post etc. How greedy and stingy can you be. Can you lock up the whole internet into your pocket? You see, there's no sense in holding onto some knowledge as though it's your personal property. Share! Share!! Share!!!<br />
<b><u>Change Mentors</u></b><br />
Once you're able to communicate with your mentors at par, you are colleagues. At this point, a wiser thing to do is to choose you mentor's mentor as your new mentor or choose someone better than your mentor as a mentor. Whether you like it or yes, there's always someone up the the ladder. Hating is diabolic and unhealthy. Humility and curiosity is key to the acquisition of knowledge. Acknowledge the fact that your aren't the best and you won't be the best but you can be among the best. Change your mentors frequently. It's a measure of how fast you're growing.<br />
<b><u>Don't Be Changed As A Mentor</u></b><br />
If your mentee chooses another mentor it means he's got to your level and you aren't growing. Keep growing your knowledge. Learn as though you're gonna live forever on earth. Find great joy in increasing your technical know-how on a day-to-day basis.<br />
<br />
<b><u>Don't Be Complacent</u></b><br />
<br />
In the land of blind men, the one-eyed man is the King. In Ghana, anything above a freaking HelloWorld is worthy of an award. That there are few techies around doesn't mean everything should be over hyped. A full grown hairy man creates a damn app which notifies you when you get a letter at the post office and it get featured in our contentless media. You build static websites and get carried on shoulders by incompetent people holding highly influential positions. Hey, village programmer, Ghana or African isn't the only place on earth. There are better programmers elsewhere who are worth looking up to. Truly, there are equally good local programmers who are worth mimicking. Have big dreams. It's not about an app which tells you how much damn calories you've burnt. Who cares if your burnt the hell out of yourself. It's only about solving the very simple problems in society. Guys, stop acting as though you're at silicon valley. Silicon valley ain't no joke. Here's silicon savannah, embrace it. Know where you are, know where you wanna go to and you'll know how to get there. Kill your pride because your pathetic degree isn't even a match for someone's primary education. You were taught Computer Science by some lecturers who haven't even written code to parse a file. Your final year project was a useless blah blah blah management system which is sitting in dust by now.<br />
I'm telling you the hard truth you've never heard and you're probably thinking "who the hell does this Pie dude think he is". Sorry man, I'm an honest and proud African who wants Africans to be known for the good things we do and not the copy-cat wanna-bees we've been for decades.<br />
<br />
Have big dreams, dream about working for intelligent tech companies across the world. Work with some of the smartest people around. Learn from them! It's not only about some half-assed software. It's not about engaging in mental masturbations. Thinking you're the best. Stop painting Africa black with your mediocre bullshit inventions.<br />
<br />
I don't think of my self as the best programmer, I only aim to be among the best in the world and that's what I'm constantly working on becoming.<br />
<br />
Get real!!!<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-7361231216388038509.post-54499521231434702762014-06-17T05:10:00.002-07:002014-06-17T05:10:58.834-07:00Learn A Pattern A Week With Pie - SingletonOur focus this week shall be on a very simple yet useful design pattern, the Singleton Design Pattern.<br />
<br />
<b><u>So What's The Singleton Design Pattern?</u></b><br />
<b><u><br /></u></b>
Like a lonely guy, a singleton class has <b>one and only one object instantiated application-wide</b>. The Singleton pattern is categorised as a <b>creational pattern</b> because it provides a very good way of instantiating objects.<br />
<br />
This pattern usually involves a single class which takes absolute responsibility of creating it's own object while ensuring no one else does and also ensuring that only one object gets created. A singleton class also provides access to it's only object directly without the need to instantiate an object of the class.<br />
<br />
Classes whose purpose is to provide application-wide services are good candidates of the singleton design pattern. To this effect, the singleton pattern is used for components like Loggers, Drivers, Thread Pools, Caches etc.<br />
<br />
<b><u>What Does It Take For A Class To Be A Singleton?</u></b><br />
<b><u><br /></u></b>
Note that, the whole essence of the singleton design pattern is to ensure that only a single instance of a class exists application-wide and this single object should only be created by the class itself. This means the following conditions should be met:<br />
<br />
1. <b><u>A Private Constructor</u></b> : The singleton class should have a private constructor to ensure that no object of the class can be created outside of the class itself. Without a public constructor no other code can create an instance of a class. Making the class' constructor private prevents other classes from creating objects of this class. In this case, only the class under discussion can create an object of it's own self.<br />
<br />
2. <b><u>A Private Static Instance</u></b> : There also need to be a private static instance of the same class that is the only instance of the class. Since an object of the class can never be created outside of the class, we'll need to explicitly instantiate an object of the class under discussion. This single instance should be made <b>static</b> and preferably <b>final</b> as well just so we wouldn't have to instantiate an object of the class (which can't be done anyways) before accessing it.<br />
<br />
3. <u style="font-weight: bold;">A Public Static Method</u> : This static public method (usually named 'getInstance()') is the global access point for the outer world to get a reference to the single instance of the class under discussion.<br />
<br />
I think we've had enough theory to get you confused now! Let's do a hands-on exercise to clear the confusion.<br />
<br />
In our hands-on exercise, we'll create a hypothetical database connector class which should help us to execute queries any where within our application. NOTE : We won't actually do any database programming here, we'll only simulate the operations.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-JwfngUud2WY/U6AstUUi2mI/AAAAAAAAAJU/yRVJc1pAmcc/s1600/DatabaseManager.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-JwfngUud2WY/U6AstUUi2mI/AAAAAAAAAJU/yRVJc1pAmcc/s1600/DatabaseManager.png" /></a></div>
<br />
<br />
In this exercise, we've created a pseudo database connection manager with a public API which is supposed to return a list of all the employees in our database. Assuming this data is so central to our application that we'll want to be able to access it anywhere in our codebase without having to explicitly instantiate objects of our DatabaseManager class, we've made our DatabaseManager class a singleton class.<br />
<br />
This means anytime we want to access the list of employees in our database, all we've to do is to call DatabaseManager.getInstance().getAllEmployees();<br />
<br />
DatabaseManager.getInstance() will return the only instance of our DatabaseManager class which we'll want to exist application-wide. We then invoke .getAllEmployees() on the instance returned.<br />
<br />
Traditionally, we would have written the following lines of codes anytime we wanted to access our employees records.<br />
<br />
DatabaseManager dbManager = new DatabaseManager();<br />
dbManager.getAllEmployees()<br />
<br />
The above code does not only demand that we type too much characters, it also wastes system resources because anytime a new DatabaseManager object is created, the database connection driver will have to establish a connection to the underlying DBMS and also perform some house-keeping chores.<br />
<br />
Implementing this class as a singleton will ensure that our database connection driver performs it's bootstrapping chores only once. It also ensures that only a single instance of this class exist which helps us to keep a global representation of our class.<br />
<br />
Note that we've used a database manager in this example but you can always use the singleton design pattern whenever you want to create a class to provide application wide services.<br />
<br />
This is the simplest way to implement a singleton class. We'll take a look at other variants later.<br />
<br />
Meanwhile, leave your questions and suggestions using the comments box below and let's learn together.<br />
<br />
Let's write clean codes one character at a time!!!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-39013363929983969272014-06-16T08:44:00.000-07:002014-06-16T08:44:21.953-07:00Learn A Pattern A Week With Pie - OverviewAs promised, we're gonna learn a new design pattern each week to make us better programmers, programmers who write clean and maintainable code. If any code was ever written by a good programmer, that code would probably not need to be commented.<br />
<br />
To make the learning easier and full of fun, am gonna make my post very simple, byte-sized chunks which can easily be learnt, understood and memorised in the shortest possible time.<br />
<br />
Today, I'll give you an overview of the various groups of design patterns out there and also learn about the GOF.<br />
<br />
<b><u>So What Is The GOF Thingy?</u></b><br />
<b><u><br /></u></b>
<u style="font-weight: bold;">GOF</u> (Gang Of Four) refers to a group of 4 authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides who in 1994 published a book titled "<i style="font-weight: bold;">Design Patterns - Elements Of Reusable Software" </i>which initiated the concept of design patterns in Software Development.<br />
<br />
I just felt I should make mention of these reverend authors and pioneers of such an important subject in Software Development since no self-respecting book or text on this subject matter would be complete without making reference to the Gang Of Four.<br />
<br />
<b><u>Types Of Design Patterns</u></b><br />
<b><u><br /></u></b>
Per the book <i style="font-weight: bold;">Design Patterns - Elements Of Reusable Software </i>written by the GOF, there are 23 design patterns classified into 3 major categories: Creational, Behavioural & Structural Design Patterns.<br />
<br />
In my subsequent posts we'll study each of these 23 design patterns identified and outlined by the GOF in their book.<br />
<br />
Meanwhile, let's take a look at the criteria for grouping these 23 design patterns into any of the 3 categories.<br />
<br />
<b>NOTE : <i>Java will be used for the code samples in all my post. It shouldn't be difficult converting those sample codes into other OOP languages!</i></b><br />
<br />
<b><u>CREATIONAL PATTERNS</u></b><br />
<b><u><br /></u></b>
Instead of using the "new" keyword in Java to instantiate new objects of classes, the creational design patterns provides ways of creating objects whiles hiding the logic for creating the objects. This gives more flexibility in deciding which object needs to be created for a given use case unlike using the "new" keyword.<br />
<br />
<b><u>BEHAVIOURAL PATTERNS</u></b><br />
<br />
These patterns are concerned with how objects within our programs communicate across their interfaces.<br />
<br />
<b><u>STRUCTURAL PATTERNS</u></b><br />
<br />
These patterns concern classes and objects compositions. In these patterns, inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.<br />
<br />
<i>Don't worry if all these seem too abstract and incomprehensible. Just hold on for a ride and things will be better once we start studying all the 23 patterns one-after-the-other.</i><br />
<i><br /></i>
<i>May today kick yesterday's ass!</i><br />
<br />
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7361231216388038509.post-14665936488566449552014-06-13T04:51:00.000-07:002014-06-13T04:51:33.570-07:00Learn A Pattern A Week With Pie - Introduction<b><u>What Are Design Patterns?</u></b><br />
<b><u><br /></u></b>
Design patterns are a documented set of best practices used by experienced object oriented programmers. These are solutions to general problems that these experienced programmers once faced during software development. Through numerous trials and errors, these solutions were finally obtained, standardised and documented over quite a substantial period of time.<br />
<br />
<b><u>Why Should I Care About Design Patterns?</u></b><br />
<b><u><br /></u></b>
Design patterns have evolved over a period of time and they provide splendid solutions to certain problems faced during software development.<br />
<br />
The un-experienced or green-horn programmer will learn software design in an easy and faster way. Learning design patterns will help you avoid common mistakes which experienced programmers made in the past. This way, you'll be saved an invaluable quantity of time which you can use to do something else.<br />
<br />
Design patterns also set a common platform for programmers. It provides a standard set of terminologies which are specific to particular scenarios. For example, a singleton design pattern signifies use of a single object application-wide so all programmers familiar with this terminology will make use of a single object and can tell each other that program is following the singleton pattern.<br />
<br />
Design patterns also set a yard stick with which we measure clean codes. Learning design patterns will help any programmer to avoid writing hard-to-maintain-code. Design patterns will help you develop software packages which are closed to modification but open for extensibility.<br />
<br />
In my own opinion, one good way of becoming a good programmer is to follow the following route:<br />
1. Choose one main-stream and one non-main-stream language. Eg Java or C#.Net & Python or Go<br />
2. Master the Syntax & Semantic of the languages you've chosen<br />
3. Master the Object Oriented Concepts & Constructs. Eg Polymorphism, Encapsulation etc<br />
4. Master Design Patterns and know how to apply them in your languages of choice.<br />
5. Write & Read a lot of code<br />
6. Never enter tomorrow being the same person you are today. Learning is a life-long process.<br />
<br />
<br />
If you enjoyed this post, join me as we learn a new design pattern every week.<br />
<br />
Enjoy your weekend!Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-7361231216388038509.post-85912105801228265772014-01-29T02:21:00.002-08:002014-01-29T02:21:53.802-08:00According JavaScript The Respect It DeservesOne common misconception and practice among developers is the assumption that we can hop into the world of JavaScript and start writing useful code simply because we already know how to program in C,C++,Java or C#.<br />
<br />
We learn how to declare variables using the <b>var </b>keyword, how to get handles to DOM elements with<br />
<b>document.getElementById("id") </b>or <b>getElementsByClassName("className") </b>how to dynamically manipulate the styles attached to DOM elements and finally register event callbacks to be invoked for specific browser events.<br />
<br />
The recent outburst of awesome JS libraries such as <a href="http://angularjs.org/" target="_blank">Angular JS</a>, <a href="http://backbonejs.org/" target="_blank">Backbone JS</a>, <a href="http://knockoutjs.com/" target="_blank">Knockout JS</a>, <a href="http://jquery.com/" target="_blank">JQuery</a>, <a href="http://d3js.org/" target="_blank">D3</a> ect proves the power of the world's most used language, JavaScript. JavaScript is the engine that powers the web of today. It's the reason for the responsive web apps we enjoy today.<br />
<br />
The power of JavaScript goes beyond mere DOM manipulations. It is a very powerful language when given the necessary respect. Though it was released prematurely by NetScape during the browser war era, JavaScript shipped with some really good stuffs. Despite the nasty side of JavaScript, it does more than simply manipulating DOM elements and handling of callbacks. The good sides of JavaScript is the reason why it was the best fit for developing <a href="http://nodejs.org/" target="_blank">Node JS</a>, a server side JavaScript engine for implementing highly responsive, non-blocking and near realtime web apps.<br />
<br />
JavaScript is an Object Oriented Programming language with constructs similar to classes, constructors and inheritance as we know from other mainstream OOP languages like C++, Java , C# etc.<br />
<br />
For most of us, our learning of JS never comes to this street of OOP. JS is really cool when used from the good side.<br />
<br />
To further build your understanding in JS, I recommend these books which I recently bought from <a href="http://leanpub.com/">leanpub</a><br />
<br />
<b>1. JavaScript, The Good Parts</b><br />
<b>2. Principles Of OOP in JavaScript</b><br />
<br />
And finally to learn more client-side JS you can try<br />
<br />
<b>3. The Definitive Guide To JavaScript</b>.<br />
<br />
Isn't it time to say hi to JS?<br />
<br />
May this year kick last year's ass!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-34552678956701677712014-01-28T09:22:00.002-08:002014-01-28T09:22:27.079-08:00Groking The Android EmulatorThe Android SDK offers a bunch of mouth-watering tools to developers to increase their productivity. Most of these tools are second-to-non when compared to the tools provided by other rival mobile platforms such as Apples iOS (XCode).<br />
<br />
One of the most outstanding tools in the Android SDK is the Android Virtual Device, A.K.A Emulator. In this post, am gonna show you how to have fun with the Android Emulator. I assume you already have your SDK setup and some ADVs created.<br />
<br />
Now run an instance of the emulators shown in your AVD Manager.<br />
Each instance of the emulator is bound to a port number which is shown on the title bar of the emulator window. My emulator's port number as at the time of this post shows 5554. (Yours may be different anyway)<br />
<br />
Now, let's connect to the running emulator via telnet.<br />
Open your terminal or command prompt and execute the following command<br />
<br />
<b>telnet localhost 5554</b> (Replace 5554 with the port number shown on your emulator)<br />
<br />
If everything goes as planned you should see an output similar to<br />
<br />
<b>Trying ::1...</b><br />
<b>telnet: connect to address ::1: Connection refused</b><br />
<b>Trying 127.0.0.1...</b><br />
<b>Connected to localhost.</b><br />
<b>Escape character is '^]'.</b><br />
<b>Android Console: type 'help' for a list of commands</b><br />
<b>OK</b><br />
<b><br /></b>If you've got this output in your terminal just jump and shout hurraaaay! (watch out for the ceiling fan)<br />
<br />
Now all is set to grok the emulator<br />
<br />
1. Let's change the network status from 3G to Edge and back<br />
Type<br />
<b>network speed edge</b><br />
Observe your emulator's signal indicator changing to show edge<br />
Now type<br />
<b>network speed 3g</b><br />
Observe your emulator's signal indicator changing to show 3G<br />
<br />
(Wait! Wait!!, don't jump yet)<br />
<br />
2.Let's simulate an incoming sms<br />
Type<b> </b><br />
<b>sms send 0200662782 "Howdy?, Mr Spanky emulator" </b>(Change the phone number)<br />
Observe your emulator's notification bar as your girlfriend drops in a new romantic message<br />
Mind you, this isn't a replacement for WhatsApp, Lol!<br />
<br />
3.Let's simulate a low-battery environment<br />
Type<br />
<b>power capacity 4</b><br />
Observe your battery indicator drop to 4%<br />
Don't keep doing this cos you don't know when ECG will get you a real low-battery situation.<br />
<br />
<b>NOTE :</b><br />
There are tonnes of command you should know of. Apply whatever you've learnt here to simulate such situation when needed to test your apps in the emulator.<br />
Want to be a groking monster? Point your browser <a href="http://developer.android.com/tools/help/emulator.html" target="_blank">here</a>.<br />
<br />
May 2014 kick 2013's flat ass!!!<br />
<br />Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-7361231216388038509.post-31369435524558238252013-12-12T07:36:00.002-08:002013-12-12T07:36:44.413-08:00Generating Barcodes In PythonThere are almost 2.7 million searches related to the term “barcode” each and every month on Google.<br />
It’s no wonder that barcoding is such a large topic for small businesses. Can you think of anything in this day and age that doesn’t have a barcode?<br />
Barcodes have revolutionized the way we do business today. They allow you to run your small business more accurately and efficiently, getting you ready for growth. You’ll look more professional too!<br />
Programmers these days are required to know just enough about barcodes in order to implement any serious shop management system or product identification system. However the barcode specification spans many pages. This means, it's impractical for any programmer to fully understand how barcodes work behind the scenes before being able to generate them from their codes.<br />
<br />
There are a lot of software libraries out there to help in the generation and scanning of barcodes. For example, the <a href="https://code.google.com/p/zxing/">ZXing library</a> is a suite of java libraries for working with barcodes from the Android platform to JSE and JEE (Servlet Containers).<br />
There is also <a href="http://barcode4j.sourceforge.net/%E2%80%8E">Barcode4J</a>, a freely available software library for generating and scanning barcodes in java.<br />
<br />
Scanning of barcodes in a shop management system is actually a quick replacement for the keyboard. That is, instead of searching products by typing lengthy product codes into the software, a barcode scanner simply scans the barcode image and feeds the product code into the software for searching.<br />
<br />
Of all the libraries around, I choose <a href="http://www.reportlab.com/">ReportLab</a>, an amazingly free python package for generating PDFs. Aside it's extensive support for PDFs, it generates all kinds of barcodes including QRCodes.<br />
<br />
The procedure for installing ReportLab is clearly laid out on their site.<br />
<br />
Now with ReportLab installed, let's get our fingers dirty with some python codes<br />
In our first example we will generate a simple PDF document showing "Hello World"<br />
Open up your text editor and type in the following codes<br />
<br />
from reportlab.pdfgen import canvas<br />
<br />
c = canvas.Canvas("hello.pdf")<br />
c.drawString(100,500,"Hello World")<br />
c.save()<br />
<br />
After executing this python code, you should see a file, "hello.pdf" in your current working directory. Open it with any PDF reader and say a big thanks to the ReportLab team for such a fantastic offer.<br />
<br />
The details of how this piece of code works is spelt out in the ReportLab documentation.<br />
<br />
Now let's generate some simple barcode. The details of the different types of barcodes are out of this post's scope but in this example we will be generating a EAN13 barcode, an european standard barcode format for most products in shop. The ReportLab library is capable of generating all other kinds of barcodes. Just read the fu*king manual.<br />
<br />
<br />
from reportlab.graphics.barcode import eanbc<br />
from reportlab.graphics.shapes import Drawing<br />
from reportlab.pdfgen import canvas<br />
from reportlab.graphics import renderPDF<br />
<br />
#Setting up canvas for pdf<br />
c = canvas.Canvas("barcode.pdf")<br />
code_number = "1234567899087" #This is the number for which the barcode is to be generated<br />
<br />
#Generating a EAN13 code<br />
barcode = eanbc.Ean13BarcodeWidget(code_number)<br />
<br />
#Drawing generated barcode onto pdf<br />
drawing = Drawing(50,10)<br />
drawing.add(barcode)<br />
renderPDF.draw(drawing,c,100,100)<br />
<br />
c.save()<br />
<br />
<br />
<br />
This is all there's to generating and saving a barcode to a PDF. Applying your own logic, you should be able to generate countless unique barcodes, print them out and stick them on your products for identification.<br />
<br />
Lemme know of your questions by commenting.<br />
<br />
Happy Coding!!!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-74016328187812046102013-11-05T12:42:00.001-08:002013-11-05T12:42:20.212-08:00Switching Android Activities : Fade Out - Fade In AnimationIn this post, I will show you how to implement a basic slide-out-slide-in transition animation when switching between Activities in an Android application.<div>
<br /></div>
<div>
Animation in Android can be implemented either in Java code or XML markup. In this post we will use the latter approach. A similar post will be published on implementing animations in Java code.</div>
<div>
<br /></div>
<div>
We are going to make some assumptions. We will assume that we have 2 activity classes, ActivityA and ActivityB. Now when a button is clicked on ActivityA, we want it to slide out and ActivityB will slide in.</div>
<div>
<br /></div>
<div>
To define the animations in xml, create a file call fade_in.xml in the anim directory found in the res folder and paste the following code.</div>
<div>
<br /></div>
<div>
NOTE : The filename could be any valid android resource name</div>
<div>
<br /></div>
<div>
CODE FOR slide_in.xml</div>
<div>
<br /></div>
<div>
<div class="p1">
<span class="s1"><?</span><span class="s2">xml</span><span class="s3"> </span>version<span class="s3">=</span><span class="s4">"1.0"</span><span class="s3"> </span>encoding<span class="s3">=</span><span class="s4">"utf-8"</span><span class="s1">?></span></div>
<div class="p2">
<span class="s1"><</span><span class="s2">set</span><span class="s3"> </span><span class="s5">xmlns:android</span><span class="s3">=</span>"http://schemas.android.com/apk/res/android"<span class="s1">></span></div>
<div class="p1">
<span class="s3"> </span><span class="s1"><</span><span class="s2">translate</span><span class="s3"> </span>android:fromXDelta<span class="s3">=</span><span class="s4">"-100%p"</span><span class="s3"> </span>android:toXDelta<span class="s3">=</span><span class="s4">"0"</span><span class="s3"> </span>android:duration<span class="s3">=</span><span class="s4">"500"</span><span class="s3"> </span><span class="s1">/></span></div>
<div class="p1">
<span class="s3"> </span><span class="s1"><</span><span class="s2">alpha</span><span class="s3"> </span>android:fromAlpha<span class="s3">=</span><span class="s4">"0.0"</span><span class="s3"> </span>android:toAlpha<span class="s3">=</span><span class="s4">"1.0"</span><span class="s3"> </span>android:duration<span class="s3">=</span><span class="s4">"100"</span><span class="s3"> </span>android:startOffset<span class="s3">=</span><span class="s4">"200"</span><span class="s3"> </span><span class="s1">/></span></div>
<div class="p3">
<br /></div>
<div class="p4">
<span class="s1"></</span>set<span class="s1">></span></div>
<div class="p4">
<span class="s1"><br /></span></div>
<div class="p4">
<span class="s1">Create another file called fade_out.xml in the anim directory found in the res folder of your project and paste in the following code. Again, the name of this file could be any valid android resource name.</span></div>
<div class="p4">
<span class="s1"><br /></span></div>
<div class="p4">
<span class="s1">CODE FOR slide_out.xml</span></div>
<div class="p4">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><?</span><span class="s2">xml</span><span class="s3"> </span>version<span class="s3">=</span><span class="s4">"1.0"</span><span class="s3"> </span>encoding<span class="s3">=</span><span class="s4">"utf-8"</span><span class="s1">?></span></div>
<div class="p2">
<span class="s1"><</span><span class="s2">set</span><span class="s3"> </span><span class="s5">xmlns:android</span><span class="s3">=</span>"http://schemas.android.com/apk/res/android"<span class="s1">></span></div>
<div class="p1">
<span class="s3"> </span><span class="s1"><</span><span class="s2">translate</span><span class="s3"> </span>android:fromXDelta<span class="s3">=</span><span class="s4">"0"</span><span class="s3"> </span>android:toXDelta<span class="s3">=</span><span class="s4">"-100%p"</span><span class="s3"> </span>android:duration<span class="s3">=</span><span class="s4">"500"</span><span class="s3"> </span><span class="s1">/></span></div>
<div class="p1">
<span class="s3"> </span><span class="s1"><</span><span class="s2">alpha</span><span class="s3"> </span>android:fromAlpha<span class="s3">=</span><span class="s4">"1.0"</span><span class="s3"> </span>android:toAlpha<span class="s3">=</span><span class="s4">"0.0"</span><span class="s3"> </span>android:duration<span class="s3">=</span><span class="s4">"100"</span><span class="s3"> </span>android:startOffset<span class="s3">=</span><span class="s4">"200"</span><span class="s3"> </span><span class="s1">/></span></div>
<div class="p3">
<br /></div>
<div class="p4">
<span class="s1">
</span></div>
<div class="p4">
<span class="s1"></</span>set<span class="s1">></span></div>
<div class="p4">
<span class="s1"><br /></span></div>
<div class="p4">
<span class="s1">EXPLANATION :</span></div>
<div class="p4">
<span class="s1"><span class="s1"><</span><span class="s2">translate</span><span class="s3"> </span>android:fromXDelta<span class="s3">=</span><span class="s4">"-100%p"</span><span class="s3"> </span>android:toXDelta<span class="s3">=</span><span class="s4">"0"</span><span class="s3"> </span>android:duration<span class="s3">=</span><span class="s4">"500"</span><span class="s3"> </span><span class="s1">/></span></span></div>
<div class="p4">
<span class="s1"><span class="s1"><br /></span></span></div>
<div class="p4">
<span class="s1"><span class="s1">The above code means the X position of the sliding Activity should change from -100 to 0 in 500 milliseconds.</span></span></div>
<div class="p4">
<span class="s1"><br /></span></div>
<div class="p4">
<span class="s1"></span></div>
<div class="p1">
<span class="s1"><</span><span class="s2">alpha</span><span class="s3"> </span>android:fromAlpha<span class="s3">=</span><span class="s4">"0.0"</span><span class="s3"> </span>android:toAlpha<span class="s3">=</span><span class="s4">"1.0"</span><span class="s3"> </span>android:duration<span class="s3">=</span><span class="s4">"100"</span><span class="s3"> </span>android:startOffset<span class="s3">=</span><span class="s4">"200"</span><span class="s3"> </span><span class="s1">/></span></div>
</div>
<div>
<span class="s1">The above code changes the transparency of the sliding Activity from 1 to 0.</span></div>
<div>
<span class="s1"><br /></span></div>
<div>
To show ActivityB following an event in ActivityA and apply the defined animations use the following code</div>
<div>
<br /></div>
<div>
<div class="p1">
startActivity(<span class="s1">new</span> Intent(ActivityA.<span class="s1">this</span>,ActivityB.<span class="s1">class</span>));</div>
<div class="p1">
<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>overridePendingTransition(R.anim.<span class="s2">slide_in</span>, R.anim.<span class="s2">slide_out</span>);</div>
<div class="p1">
<br /></div>
<div class="p1">
If you don't understand anything just write it in a comment and get it answered.</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7361231216388038509.post-44705126783244702932013-11-02T06:41:00.001-07:002013-11-02T06:41:11.962-07:00Africa Reborn<span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;">Many Africans want to be the Bill Gate or Zuckerberg or Steve Jobs etc of Africa. How about someone in America wanting to be the next Kofi Mensah or Araba Atta or the next you of America. Why habour such small dreams in our empty big heads. We proudly walk in town making noise about degrees. Degrees we earned cheaply by sitting in classes with equally empty headed brothers. Degrees we earned by cramming books into our heads without any practical experiences. Degrees in universities where a 4th year physics student can't even identify a common resistor or diode.</span><br style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;" /><span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;">Even without working hard, we have accepted defeat. We never want the truth to be spoken and when someone does, we call him arrogant and braggy. We can't even distinguish between confidence and arrogance. Worst of it all, we proudly call them "too known". What on earth is the word "too known" supposed to mean. From childhood we are taught not to fight for what's right. We shun teamwork and welcome the I want it all attitude. This is what is killing us. Corruption all over. Someone is willing to gimme some money I haven't worked for and he sees nothing wrong with it. I will put his sorry ass in jail soon. I stand for seriousness and reality. I dont live in a utopian world where all is fantastic. I believe in the ups and downs in life. This is what many are trying to skip.</span><br style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;" /><span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;">You think because you have a crappy degree you should drive that limousine and live in a mansion? The world has changed and so should you. The wealth of this world is no more for academicians. Its for problem solvers.</span><br style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;" /><span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;">Renew your mind and have a better life. Dont let people's thought about you affect your thought process. Be bold and live by faith and action. Life is never a war. Everything in life will be a struggle to you if you see it as a war. Let's get real oo dear Africans. Its a blessing to be black. I see a serious Africa rising and the noise making Africa sinking. Where will you be during this revolution. If you do well, we will praise you. </span><a data-hovercard="/ajax/hovercard/user.php?id=100000499052504&extragetparams=%7B%22directed_target_id%22%3A0%7D" href="https://www.facebook.com/godwin.amefia?directed_target_id=0" style="background-color: white; color: #3b5998; cursor: pointer; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px; text-decoration: none;">Godwin Amefia</a><span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;">, congrats! Keep going and never be a noise maker. </span><a data-hovercard="/ajax/hovercard/user.php?id=100000223623324&extragetparams=%7B%22directed_target_id%22%3A0%7D" href="https://www.facebook.com/yehuza?directed_target_id=0" style="background-color: white; color: #3b5998; cursor: pointer; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px; text-decoration: none;">Rasheeda Yehuza</a><span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;"> keep championing your course. The journey is the reward.</span><br style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;" /><span style="background-color: white; color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 13px; line-height: 17px;">Yes, am a HATER, hater of CRAP.</span>Unknownnoreply@blogger.com0