Programming – fmachado dot com http://blog.fmachado.com Keep walking... Thu, 01 Sep 2016 15:32:38 +0000 en-US hourly 1 https://wordpress.org/?v=4.6 Autobid bot for mukirana.com http://blog.fmachado.com/autobid-bot-for-mukirana-com/ Wed, 23 Apr 2014 01:30:51 +0000 http://blog.fmachado.com/?p=330 […]]]> I was cleaning up my trashbin when I found this Javascript code created back in 2010 for autobid on mukirana.com (a brazilian penny auction website). I don’t think they are worried with this kind of fraud because they still are susceptible to this autobid mechanism.

This code will autobid when remains only 2 seconds or less. By the way, it won’t work without some minor fixes.

var interv = window.setInterval(function () {
    // replace '00000' with the item code
    var id = "00000";
    // replace 'yournick' with the nickname that you use.
    var nick = "yournick";
    try {
        var e1 = document.getElementById("current_time_auction_" + id);
        var c1 = (e1 != null) ? parseInt(e1.innerText) : -1;
        if (c1 > 0 && c1 <= 2) {
            var e2 = document.getElementById("current_username_auction_" + id);
            var c2 = (e2 != null) ? e2.innerText : "";
            if (c2.toString() != "" && c2.toString() != nick) {
                e2.innerText = nick;
                $("submit_auction_" + id).click();
            }
        }
    } catch (err) {
        return;
    }
}, 300);

]]>
Algorithms and Data Structures – from A to Z http://blog.fmachado.com/algorithms-and-data-structures-from-a-to-z/ Wed, 11 Sep 2013 10:50:21 +0000 http://blog.fmachado.com/?p=315 Did you know that the NIST (National Institute of Standards and Technology) have a big dictionary of algorithms and data structures? Have you tried to implement a bozo sort algorithm? Do you know why a balanced BST is called AVL tree? Check it out at http://xlinux.nist.gov/dads/.

]]>
Are you a good programmer? http://blog.fmachado.com/are-you-a-good-programmer/ Mon, 09 Sep 2013 23:09:21 +0000 http://blog.fmachado.com/?p=235 […]]]> Every single day in the last few years I do almost the same thing when I wake up (well, probably you do too). Anyway, during my quick breakfast I ask myself if I did everything possible to be a better person (as father, co-worker, …) than the day before, I think about my family and things that we have to do together and, finally, about my daily tasks at work.

But what relation does this daily routine description have to do with being a good programmer? Well, I’m starting to ask myself everyday if I am a good programmer and, from a specific point of view, my answer is: no, I am not. I think that the first thing to do is acknowledge this “defect” and work to fix it. Unfortunately I have to say that probably you are an amateur or an average programmer.

Let’s take a step back and try to answer…

What is a good programmer?

I found this lecture from Richard Buckland, a professor from UNSW, which can give you the big picture:

I know, you don’t have time to watch a 55min. video so here are the points: he walks through his past lectures showing how the students went from basics to advanced topics; start learning the basics and practice until you think your are good enough and then continue practicing because there is much more that you have to learn.

But this is the common sense! If you want to be really good in any area, you have to practice! So, let’s establish the following statement:

Statement 1: If you want to become a great programmer, you have to practice. How long? Until the end of the world (or your professional career, which one comes first).

I think that the statement above is not complete because I didn’t tell you what you have to study/practice so, let’s take someone as a reference: Jaehyun Park. This guy (who owns a PhD :)) won a lot of programming contests and competitions (ICPC, IOI). I have no doubts that he is a great programmer.

(Let’s talk about being an average programmer and still be able to earn a lot of money on another post.)

Statement 2: If you want to become a great programmer, you have to understand the basics: recursion, abstract data types, …

I think that If you still don’t know how to create a common abstract data type from scratch or write a recursive code, if you don’t know what the order of growth classifications and if you avoid to learn other subjects related with algorithms, you are far from having the “good programmer” title. If you skipped these classes or you never read about these topics, take my words: use your free time to learn about it or you’ll NEVER get a good job.

Back to the beginning of this text, I wrote that I don’t think I am a good programmer. Why? Because I’m still struggling to solve challenges from programming contests. I spent almost a day to solve a problem at codility.com while someone took 24 minutes. I have to say that I couldn’t sleep well at night after the test because I couldn’t stop thinking about how I failed. I realized that I have to get back to the basics and this is what I’m doing now.

Statement 3: If you want to become a great programmer, you have to recursively identify your weak spots and improve them.


Classes that I’m taking (again)

Every single minute that I have away from my work I’m spending to learn more, including reading at lunch/dinner and listening while I’m taking shower (yes, sometimes I’m just listening to the class!).

Books that I am reading

Can you believe that I am taking classes with Robert Sedgewick? And you could do the same? Yes! You can watch his lectures at coursera.com for free. He is the author of the first book listed below: Algorithms (4th Edition).

Algorithms (4th Edition)    The Algorithm Design Manual    Problems on Algorithms

Books that are queued

I found these books excellent choices if you want to solve challenging problems and be able to check and learn with the answers.

Elements of Programming Interviews: 300 Questions and Solutions    Cracking the Coding Interview: 150 Programming Questions and Solutions    Programming Challenges: The Programming Contest Training Manual    Algorithmic Puzzles

“Do you really need all this?”

My answer is “yes, I do”. Of course I won’t create a linked list or a tree from scratch to use in my daily work when I have a LinkedList and TreeMap (a Red-Black tree) but I have to know, for example, that a Java LinkedList performs O(1) to add an element, Ω(1) and O(n/2) to remove an element (“Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.”).

Can an average programmer be a good full stack developer?

Yes and I think I’m an excellent full stack developer. I can assure you that I have learned a lot in my 20 years of professional life (hi-five if you had used these machines) and, until now, I only have heard good compliments from my bosses so, I think I’m on the right path.

]]>
SQLite and Sqliteman with Mac OSX http://blog.fmachado.com/sqlite-and-sqliteman-with-mac-os-x/ Tue, 01 Jan 2013 17:00:48 +0000 http://blog.fmachado.com/?p=213 […]]]> If you want a free and open-source “Database Manager” for SQLite running on Mac OS X, I would suggest you to stick with Sqliteman. I think this is the best open-source tool to handle sqlite databases on Mac OS. Check their website for more information about features and screenshots.

How to install on Mac OS X

There is no version available for download on Sqliteman website and you’ll have to install using MacPorts:

hell:~ fmachado$ sudo port install sqliteman

 “QSqlDatabase: QSQLITE driver not loaded” error

I got this error and was a bit painful to figure out how to fix it. Anyway, if you get this error when trying to open a SQLite database, all you have to do is install “qt4-mac-sqlite3-plugin”.

hell:~ fmachado$ sudo port install qt4-mac-sqlite3-plugin

🙂

]]>
OCPJP6 exam question – serialization http://blog.fmachado.com/ocpjp6-exam-question-serialization/ Sat, 30 Jun 2012 04:06:12 +0000 http://blog.fmachado.com/?p=179 […]]]> I was reading the SCJP6 book from Kathy Sierra and Bert Bates (one of the most prestigious books if you are pursuing the Oracle Certification for Java SE 6 Programmer) and I found a question that will blow your mind. Well, at least my reaction was something like “wtf! there must be an errata somewhere…”.

import java.io.*;

public class TestSer {
	public static void main(String[] args) {
		SpecialSerial s = new SpecialSerial();
		try {
			ObjectOutputStream os = new ObjectOutputStream(
			new FileOutputStream("myFile"));
			os.writeObject(s); os.close();
			System.out.print(++s.z + " ");	

			ObjectInputStream is = new ObjectInputStream(
			new FileInputStream("myFile"));
			SpecialSerial s2 = (SpecialSerial)is.readObject();
			is.close();
			System.out.println(s2.y + " " + s2.z);
		} catch (Exception x) {System.out.println("exc"); }
	}
}
class SpecialSerial implements Serializable {
	transient int y = 7;
	static int z = 9;
}

Which are true? (Choose all that apply.)

  • A. Compilation fails
  • B. The output is 10 0 9
  • C. The output is 10 0 10
  • D. The output is 10 7 9
  • E. The output is 10 7 10
  • F. In order to alter the standard deserialization process you would implement the readObject() method in SpecialSerial
  • G. In order to alter the standard deserialization process you would implement the defaultReadObject() method in SpecialSerial

My answer was B but the correct answer is “C and F”. Ok, I missed the “F” one and the entire question but why “C” ?!?!?!

What the heck the guys behind exams and certifications think when they are creating evil questions like this one.  Probably you know that static variables aren’t serialized, right? So, why SpecialSerial.z has 10 instead of 9 ? Because “z” is static and any SpecialSerial instance created or unserialized during the execution of this Java application will always have z = 10. 😉

]]>