Archive for November 2009
Great Reminder of the Importance Of Money
I follow an interesting blog that focuses on money from the perspective of Ayn Rand and her amazing book “Atlas Shrugged”. The posted a great article that I want to link to because this speech by Francisco is so important and so applicable in our day.
My Money Shrugged — Gold And Money
Thanks guys!
One of the most annoying things with javascript is trying to see what is inside of an object. In python you simply print (‘attributes=%s’%dir(obj)), and in php you simply use var_dump(obj), or if you want to format it into a string, you can use echo “attributes=” . var_export(obj) ; But with Javascript I really haven’t had an easy way to introspect the attributes of an object. Until now.
I have been using a great tool for debugging javascript called FireBug, it is a plugin for firefox. So, firebug has a way to do object introspection via the DOM tab. When you get an object that you want to analyze simply do something like this in your code (at a global level) var MYOBJECTREFERENCE = new Object(); Now, wherever you have access to that object you want to introspect (in an event handler or whatever), you simply say MYOBJECTREFERENCE.XYZ = obj; Then, refresh, trigger whatever event it took to generate obj, and then look in firebug’s DOM explorer window for MYOBJECTREFERENCE.XYZ.
YAY! Now there is an easy way to introspect objects in javascript. If you know of other ways to do this, please post them for us all to see.
Eric
UPDATE: 12/8/2009
I found another way to do this. The code is from RefactorMyCode.com . Mine is a little different because I was getting errors and I had to protect against them a bit… Here you go!
function odump(obj, depth, max) {
depth = depth || 0;
max = max || 2;
if (depth > max)
return false;
var indent = "";
for (var i = 0; i < depth; i++)
indent += " ";
var output = "";
for (var key in obj){
// skiplist
if (key == "domConfig" || key == "selectionStart" || key == "selectionEnd" || key == "schemaTypeInfo") {
output += "\n" + indent + key + "**: ";
} else {
try {
output += "\n" + indent + key + ": ";
switch (typeof obj[key]){
case "object": output += odump(obj[key], depth + 1, max); break;
case "function": output += "function"; break;
default: output += obj[key]; break;
}
} catch(err) {
alert("add key=" + key + " to your skiplist because of: err=" + err);
}
}
}
return output;
}
This is from last week at Solitude. I have since gotten a new board that is amazing! I got an Escape from neivasnowboards, it rocks. I will do a review and pictures of it later. But for today, here is early season photos from my first trip. Note, I went yesterday and it was like 50 times better than these shots, so fun in fact that I forgot to pull out my phone and grab photos… Oh well
Headed up tomorrow to get the kids on the run and get them learning, so maybe I will take a few more pix and put them on here.
Eric
I had to write something today in javascript that used for loops. No big deal, but usually I put it into a separate .js file, in this case I had to put it right there in the html. This created a little problem that I thought I would write about to help remind myself and provide a little guidance to others.
Less Than ‘Test’ In HTML
The problem arises when the html parser gets involved and runs into the javascript which was supposed to be ignored. Usually I will put almost all the javascript into a separate .js file so that things are cleaner, but in this case, I just need to do a quick loop right in the html. So, I used a <script tag. Unfortunately for me, the i<n loop invariance test (the end of loop test) uses a symbol (<) which is the start of an html tag open or close. I don’t know if this problem occurs when using a simple html file or not, but I am using xhtml and it really broke things.
Here is the header of my xhtml file.
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Here is my for loop code.
<script type="text/javascript">
for (var i=0; i<10; i++) {
alert("test: " + i);
}
</script>
Well the xhtml parsing freaks out when it sees the ‘i<10′ part, because < is obviously looking similar to a tag opening or closing. So at first I tried to put an html comment around it using <!– XXX –> but then my javascript wasn’t even being executed. So I had to eventually use a CDATA section like this.
<![CDATA[
for (var i=0; i<10; i++) {
alert("test: " + i);
}
]]
This was a good solution that worked for me.
Once I got the loop working, I encountered another problem.
Iterating Over Arrays Can Be Weird
In Java or C or C++ or python etc, we typically iterate over each item in an array and index with a counter. We just stop looking when the index has reached the max number of elements (minus 1) in that array.
In javascript things are different because arrays are really objects with properties. Therefore if you are trying to use the .lenght attribute (like java) you may be surprised. What I found was that
I was getting as the last item in the array an ‘undefined’ element.
for (var i=0; i<all_inputs.length;i++) {
alert("input: " + i + ") " + all_inputs[i]);
}
So, the solution is to do everything the same except for the loop invariance test. Here we just say to loop while the i’th element is not undefined. In other languages, you know that this will generate a array out of bounds type exception, but since this is really checking properties of an object, things are a little different.
for (var i=0;undefined != all_inputs[i];i++) {
alert("input: " + i + ") " + all_inputs[i]);
}
And, those are just some handy things to remember next time you are making for loops in your html code and iterating over array elements.
for (var i=0; i<10; i++) { alert("test: " + i); }
How To Delete Annoying Twitter Direct Messages
If you have used twitter for very long then you know that some people really enjoy sending direct messages (DMs). This is very annoying to me because they are usually just spam and the person wants me to click on their ad or something. Now, don’t get me wrong, I am not opposed to ads. In fact a targeted ad for something that I am interested in is very valuable to me. I just don’t like broadcast spam that fills my inbox. I am not kidding when I tell you that I had to delete 2,003 DMs from my twitter account today. It was a pain at first, until I built a little tool to do it. Now, from my tool it is very easy. This tool is a python script that you run from the command line. Remember, that python must be in your PATH for this to work, if it is not, then you will have to add it, or run python by specifying the whole path. This will work Linux, Windows, Mac, etc, you just have to install python first.
So, here is how you delete all DMs.
python twitter_tool.py delete myuser mypass all
How To Run The Twitter List Messages / Delete Messages
Obviously my script is called twitter_tool.py here are the syntax help messages.
syntax: twitter_tool.py [list | delete ] twituser twitpass [ maxmessages | all ]
In the syntax message, you can list or delete all your messages, or up to a certain number of messages. A nice way to run it is where you view 10 messages, then delete them, then repeat. Like this…
$ python twitter_tool.py list myuser mypass 10 from: blablabla date: Sat Nov 14 22:53:14 +0000 2009 You Can Find It Here http://somespammylink.spam ----------------------------------------- $ python twitter_tool.py delete myuser mypass 10 deleting message 559771108 from blablabla $
How To Run The Twitter Unfollow Command
Now what if I am cruising through my messages and I spot something that is really offensive or spammy and I just want to get away from that user. I can easily unfollow them with the same tool. Here is an example.
python twitter_tool.py unfollow myuser mypass SomeAnnyoingUser
The End
Well, that is it. A simple tool that does 3 jobs. And you are welcome to download and use the tool.
Click here to get twitter_tool.py
*** UPDATE *** Click here to get twitter_tool.py that has the ability to search for other twitter users… For example, to search for people with the word snowboard in their name, you would do this
python bin/twitter_tool.py searchpeople myuser mypass snowboard
NOTE: you will probably have to Right Click -> Save As to get the file, then save it as twitter_tool.py (i.e. you must remove the .txt extension).
Follow @bigconcept on Twitter
I case you are just joining me, I am reviewing Napoleon Hill’s book, A Year of Growing Rich, 52 Steps To Achieving Life’s Rewards. Week 4 was a really informational chapter. It is called “Some Succeed, Others Fail… Why?”. It is a chapter that compares the behavior of successful people to that of people who fail. Below I will list the characteristics of successful people. I won’t get into the failure behaviors, basically they are the opposite of the successful person’s behaviors, and we don’t want to focus too much on them anyhow.
Specific Behaviors of Successful People
- Know what you want and have a plan for getting it.
- Believe in your ability to get what you want.
- Devote a major portion of your time to acquire what you want.
- Cooperate in a friendly spirit to carry out your plans and purposes.
- Think before you speak.
- Emphasize what you like about people.
- Express opinions only after becoming fully informed.
- Budget your time and money (live within your means).
- Be open minded and tolerant.
- Know what is going in in the world.
- Keep a positive outlook on life, at all times.
- Have a great respect for our Creator, and express it.
I love the following statement by Napoleon Hill in this chapter.
The successful person keeps her mind and outlook on life positive at all times. She recognizes that the space she occupies in the world and the success she enjoys depend upon the quality and quantity of service she renders. She makes it a habit to render more service than she promises. The failure looks for “something for nothing,” or something under the table which she did not earn. And when she fails to get it, she blames the greed of others.
These are traits that I am trying to adopt in my life. I hope that you will too. Then we can be successful together.
Eric
This is a great chapter. I feel very motivated to continue on with my work again. It is so important to do the things that we need to do which will keep us motivated and working away at our vision. So, here are some notes that I want to share on this chapter.
Motivate Yourself to Achieve Success
Mr. Hill said that one of the greatest rewards for success is not necessarily monetary (although that is important), but it is the feeling of satisfaction that you have done a job well. In answer to his own question, “How can you motivate yourself to succeed?” he answers, “Develop a burning desire for something that you wish to have in order to reach a greater goal you have set for yourself. Remember, there is a difference between merely wishing for something and deciding definitely that you are going to have it”.
How to Have a Burning Desire
And what about after you get that “burning desire”? He says this, “Once you have that burning desire, you will develop an intensity of purpose that will allow you to simply brush aside obstacles that seemed insurmountable before. All things are possible to the person who believes that they are possible“.
Then he gives some very powerful steps that we must take.
- Set yourself a definite goal in life
- Write it down
- Commit it to memory
- Direct every thought and all your energies to making it come true
Setbacks and Challenges
What about challenges, what about setbacks? Napoleon says “Instead of letting momentary setbacks throw you off course, search in them for the seed of an equivalent benefit which can help you get back on track to attaining your goal.”
So, I have been completely swamped by my software project for my biggest client and have not progressed as I wanted on my tools that I am working on in my spare time (i.e. I haven’t had spare time lately). So, instead of getting down or forgetting about it, I have to look for a benefit that I have gained because of this setback. It is there, there is something in this that will help me to reach my goal.
Start Where You Are
Finally, let me end with Napoleon Hills final paragraph about starting where you are.
“Remember, Whatever the mind of man can conceive and believe, the mind of man can achieve. The person determined to attain success starts where he stands, making the best of whatever tools he has and acquiring whatever else he needs along the way. Start from wherever you stand–today.”





