Tags related to tag hacks
Monday, June 25. 2007
Automated Web Developer Tests using Selenium, Emacs, and MozRepl
One of the biggest hassles with web development is the lack of any real test harness. I have lamented about this before, especially when it comes to testing such ephemerals as an elements height, width, etc. So far the best tests I have run into are your two eyes, which is fine when you are working and testing on one discreet component... but web sites, especially the ones I work on, tend to be more then just 1 or two discreet components.
Enter Selenium IDE. The Selenium IDE provides you with a method to record and execute automated tests of your website. It is easy to use, and hella cool. It can test things like the existence of an element, the text contained inside of an element, its width, height, position, etc. Using selenium, you can build yourself unit tests. This is especially useful and powerful if you happen to be one of the unlucky bastards faced with writing code in JSTL, SMARTY, or some other templating-language-that-needs-to-die. Now you finally have unit tests.
Using Selenium, the testing process is a little more automated. More importantly, you can build a series of regression tests, to ensure the stability of your web application.
There is another piece of the web-development puzzle here, and that is the Moz Repl. An REPL is a Read Eval Print Loop, basically an interactive command interpreter that you can feed commands to, and experiment with. the Moz REPL is a javascript version, that lets you inspect and modify any Javascript object in the browser. This REPL is telnet enabled, in fact, there is even a way to make Emacs talk to this REPL, so you can poke around the browser from within your text editor. This is amazingly powerful in two regards:
So the final piece of the puzzle is something I call Selenemacs. It is a global emacs minor mode, in conjunction with some simple javascript that will script selenium, and provide you with feedback on whether or not its tests pass or fail.
Update 2007-07-09: new versions (Version 0.2) added
Here are the two files:
Here is how you use them:
First, download the MozREPL and Selenium IDE extensions for firefox
Edit selenemacs.el to make sure that the variable selenemacs-js-file points to selenemacs.js
Enable the MozRepl (Tools->MozLab->StartREPL)
Load up selenemacs.el inside emacs (load-file "path/to/selenemacs.el") works
Enable the minor mode selenemacs-minor-mode
Record your test in SeleniumIDE
Use the emacs command selenemacs-execute-test to launch the test, its shortcut is C-c C-s C-e
Emacs tells you if the test passed or failed.
The idea here is that you write your test, and stop using your eyes to test the results of your coding to the browser, but instead use Selenium. This is especially good if you are doing multi-stage and repetitive like testing logins, searches, etc. You can code and test right inside emacs, and only have to switch to the browser to verify that your tests actually passed.
These files also show an interesting way to script mozilla through emacs. The next step of course is to get emacs to start interacting with Firebug.
Enter Selenium IDE. The Selenium IDE provides you with a method to record and execute automated tests of your website. It is easy to use, and hella cool. It can test things like the existence of an element, the text contained inside of an element, its width, height, position, etc. Using selenium, you can build yourself unit tests. This is especially useful and powerful if you happen to be one of the unlucky bastards faced with writing code in JSTL, SMARTY, or some other templating-language-that-needs-to-die. Now you finally have unit tests.
Using Selenium, the testing process is a little more automated. More importantly, you can build a series of regression tests, to ensure the stability of your web application.
There is another piece of the web-development puzzle here, and that is the Moz Repl. An REPL is a Read Eval Print Loop, basically an interactive command interpreter that you can feed commands to, and experiment with. the Moz REPL is a javascript version, that lets you inspect and modify any Javascript object in the browser. This REPL is telnet enabled, in fact, there is even a way to make Emacs talk to this REPL, so you can poke around the browser from within your text editor. This is amazingly powerful in two regards:
- you can script your browser from emacs
- you can edit code inside emacs, and send it right to the javascript interpreter for testing, and evn install it on the current page
So the final piece of the puzzle is something I call Selenemacs. It is a global emacs minor mode, in conjunction with some simple javascript that will script selenium, and provide you with feedback on whether or not its tests pass or fail.
Update 2007-07-09: new versions (Version 0.2) added
Here are the two files:
Here is how you use them:
First, download the MozREPL and Selenium IDE extensions for firefox
Edit selenemacs.el to make sure that the variable selenemacs-js-file points to selenemacs.js
Enable the MozRepl (Tools->MozLab->StartREPL)
Load up selenemacs.el inside emacs (load-file "path/to/selenemacs.el") works
Enable the minor mode selenemacs-minor-mode
Record your test in SeleniumIDE
Use the emacs command selenemacs-execute-test to launch the test, its shortcut is C-c C-s C-e
Emacs tells you if the test passed or failed.
The idea here is that you write your test, and stop using your eyes to test the results of your coding to the browser, but instead use Selenium. This is especially good if you are doing multi-stage and repetitive like testing logins, searches, etc. You can code and test right inside emacs, and only have to switch to the browser to verify that your tests actually passed.
These files also show an interesting way to script mozilla through emacs. The next step of course is to get emacs to start interacting with Firebug.
Tuesday, January 9. 2007
I think I'm learning Japanese... I really think so.
The very thought me taking that final step of being an Otaku Gaijin fills me with a certain amount of pride and dread (pread? dride?). Nothing says "Hard Core Geek" like learning Japanese.
What has made me take the plunge is a rather long rant, involving a whiteboard, lots of beers, and Jason Stormchild. He was showing me some Kanji, and how some kanji have an etymological basis. To the right, you can see the kanji for 'sun' and 'moon'. When you put those two characters together, you get the kanji for 'bright'. Similarly, the kanji for 'forest', is 3 trees done up together. Finally, there is the kanji for 'east', which is a combination of the kanji for sun and the kanji for tree, so it is like the sun rising in the east, peeking out through the trees.
It was this explanation (which, was way more poetically put by Jason) plus the repeated assertions that I would be one of the people to get a lot out of learning kanji that made me take the plunge. Learning a new verbal language has the same kind of potential as learning a new programming language, except, I rather suspect, that instead of changing the way you think about programming, it changes the way you think about thinking.
Some Example Kanji
It was this explanation (which, was way more poetically put by Jason) plus the repeated assertions that I would be one of the people to get a lot out of learning kanji that made me take the plunge. Learning a new verbal language has the same kind of potential as learning a new programming language, except, I rather suspect, that instead of changing the way you think about programming, it changes the way you think about thinking.
Wednesday, December 27. 2006
A Tale of Two Selves
The x in me likes the y,
but the a in me likes the b
But this separation of selves is much more subtle then a distinct dumb-ass-instant-grat-self and the monocle-wearing-disciplined-self. Not only are the selves that we wear when at home, work, or the club are all different selves, but the selves that we present to our bosses and our team members are different. The same me that comes home from work is not really the same me that kisses my daughter "goodnight". So what happens when one self wants something, but the other does not? Which self wins? Which self should win? Which self is the real me? Which me should make the decisions?
What happens at 5:30?
The Calgary Light Rail Transit is horrible at rush hour. If you are trying to catch a train at 5:00PM, you will end up waiting anywhere between 5 and 30 mins for one. So instead of waiting for a train, in which I will invariably be squished, and smell ungodly BO, I usually play Quake 3 at work for half an hour, with the rest of the team. We all have fun, get out some yuck-stress, and it's—and I say this with an ironic twist, as to not lose my street credibility—"team building". At 6:00 however, bus service goes from being "peak" to "off-peak" which means buses come every half an hour, and trains every 15 mins. Turning a commute that is usually 30-45 mins into an epic 1-1 1/2 hour journey.This is very deeply connected to the "50K feet", and "runway" views of your life that David Allen talks about. For those that don't know, the "Runway" is whats going on (and what needs to be done) right now. Then there are the views of your life, getting higher and higher. 10K feet being your current projects, 20K feet being the projects for this year, all the way up to 50K feet, which is your life's goal, your raison d'etre. The thing is, that you have to have a clear line between the runway and 50K feet. If your nose is pointed at the British Isles, but you want to go to Japan, then you're going to have to make an in-air turn, and that is going to be painful.
Now the first urge is to say "Well okay, lets turn this plane west, and be done with it.", which is to say, buckle down and get to reaching your goals. But if your nose is pointed East, but your goals are pointed West, which is out of sync? Do you need a course correction at a higher level or a lower level? In reality, two goals aren't quite so mutually exclusive. That being said, if my 50K feet goals are in sync with the selves-that-I-am-in-my-daily-life, then it is much easier to achieve them. But if you really feel that your life's work is to save the world, and you are cranking widgets from 9-5, then you have a problem. Maybe you need to reset your 50K view, and choose a different direction for your life, maybe you need to work toward quitting your job and figure out how to save the world instead, or perhaps you need to re-evaluate how the widget cranking is helping you to save the world.
I think that the crux of getting your selves to work together as a unified country, instead of a civil war is to start by extending lines down from the 50K view. To meet your goal of changing the world, you need to eventually boil that down to action steps and this process of boiling down your life's work means starting at your top, with things like retirement goals and the goals you have for the next 50 years, and working your way down the ladder to 20, 10, and 5 years, until you get down to where the rubber meets the road (or runway in this extended analogy). As you start this boiling down task, you might see goals that work their way upward. In fact, ideally, you will have a situation where some of your more immediate goals can start to fall in sync with the loftier goals as a person.
So when magicians are talking about their true-will, this is where they are going with it. To understand ones desires, from the base desires like,"ugh! want to have crazy-sex shoot big imaginary virtual guns at people and eat cookie dough ice cream!" all the way up to the lofty "I must save the world—no one else is." is to get at the heart of ones "true will".
Saturday, October 21. 2006
Shells Parent Hacks Core Dump
Jonnays Note: Shell posted a bunch of hints and tips to Parent Hacks, or a site that was linked there, and I thought I would cross post it here as well, cause they are that good.
I get an empty journal book for the child every year. I tape or glue memory stuff in there like pamphlets from the zoo, birthday cards, swim lessons certificates etc. I put the dates on them and the dates on important things that happened that year. The rest of the book is open for the child to fill. It is a keepsake and teaches the child to keep a journal or sketchbook which is an important skill at any age.
There is nothing like opening a present on Christmas Eve. A taster for the next morning. I get my kids Christmas pajamas that they can open on Christmas Eve so they are festive for the morning.
Instead of making bottles up ahead of time, I put the powder in a bottle, then when it is time for baby to have bottle, just add warm water. You don't have to keep the bottles in the fridge or cooler, and you don't have to heat it up.
I have a sure fire way of getting a child to sleep through the night at a very early age. Pick a simple short book (Sandra boynton is great) and make that the last thing before you put the child in bed and only at night, never for nap. Do this from a very early age, I started at 3 weeks. This book becomes the cue for bedtime. The child knows what to expect. We did this with my daughter since she was 3 weeks old till she was about 1 1/2. She has always been a great sleeper.
When my kids would fight or have a hard time learning something I would tell them the special bedtime stories. I would change their names just slightly and tell them a story about these kids. I would change the details slightly about the issue they were dealing with. They would get involved in the story and I would ask them questions about how the kids in the story should deal with the issue. They would come up with solutions looking at it from an outsider point of view, which is easier to do without having the emotional aspect to deal with as well. They were able to see both sides. Then I thought these were the last thoughts in their heads before they went to bed so maybe it would sink in. It really seemed to work.
Making bottles ahead of time can be a hassle. I found if I used the gravy maker from Tupperware it was much easier. It has markings on it for the water. Close it up and shake and put it in the fridge.
Instead of babyproofing everything, I leave stuff on the shelves and tables within reach that is adult only but safe and not breakable. When baby starts to play with the items at an early age I teach them no. I say no, that they aren't allowed to play with it and remove them from the temptation. It is almost enough to drive you crazy for a long time, but if you stick to it, they learn at a very early age. I can take my daughter anywhere and people don't have to start moving things as soon as the child walks into their house.
When the child shares I make a big deal out of it. Tell them how wonderful it is that they are sharing with plenty of clapping. They learn that sharing is not something to get upset about, but rather it is something fun that makes everyone happy.
I have a hard time bathing the child in the bathtub. I get a backache leaning over. When the baby is small enough, till they are about 1 or even more, I bath them in the kitchen sink.
When feeding baby I give the baby a spoon of their own so they learn how to use it early.
Don't hide the small arguements from the child. Do it without anger and let them see the resolution as well so that they can learn how do deal with negatives.
Remember that the child is not doing whatever it is that is making you angry "to you" or to be bad. Try to understand "why" they are doing it. For instance, if the child is throwing food on the floor they might be doing it cause it made a really neat sound. This doesn't mean that they are allowed to do it, but it will help with the way you deal with it without anger.
Say please and thank you, sorry and your welcome on a regular basis. You won't have to spend alot of time teaching your child this, they will pick it up from watching you.
I find that if they child has boundries they are much happier. They don't have the skills or the need to make decisions. However, flexibility is just as important. Sometimes, they need to feel that they have a say in what is going on.
I get an empty journal book for the child every year. I tape or glue memory stuff in there like pamphlets from the zoo, birthday cards, swim lessons certificates etc. I put the dates on them and the dates on important things that happened that year. The rest of the book is open for the child to fill. It is a keepsake and teaches the child to keep a journal or sketchbook which is an important skill at any age.
There is nothing like opening a present on Christmas Eve. A taster for the next morning. I get my kids Christmas pajamas that they can open on Christmas Eve so they are festive for the morning.
Instead of making bottles up ahead of time, I put the powder in a bottle, then when it is time for baby to have bottle, just add warm water. You don't have to keep the bottles in the fridge or cooler, and you don't have to heat it up.
I have a sure fire way of getting a child to sleep through the night at a very early age. Pick a simple short book (Sandra boynton is great) and make that the last thing before you put the child in bed and only at night, never for nap. Do this from a very early age, I started at 3 weeks. This book becomes the cue for bedtime. The child knows what to expect. We did this with my daughter since she was 3 weeks old till she was about 1 1/2. She has always been a great sleeper.
When my kids would fight or have a hard time learning something I would tell them the special bedtime stories. I would change their names just slightly and tell them a story about these kids. I would change the details slightly about the issue they were dealing with. They would get involved in the story and I would ask them questions about how the kids in the story should deal with the issue. They would come up with solutions looking at it from an outsider point of view, which is easier to do without having the emotional aspect to deal with as well. They were able to see both sides. Then I thought these were the last thoughts in their heads before they went to bed so maybe it would sink in. It really seemed to work.
Making bottles ahead of time can be a hassle. I found if I used the gravy maker from Tupperware it was much easier. It has markings on it for the water. Close it up and shake and put it in the fridge.
Instead of babyproofing everything, I leave stuff on the shelves and tables within reach that is adult only but safe and not breakable. When baby starts to play with the items at an early age I teach them no. I say no, that they aren't allowed to play with it and remove them from the temptation. It is almost enough to drive you crazy for a long time, but if you stick to it, they learn at a very early age. I can take my daughter anywhere and people don't have to start moving things as soon as the child walks into their house.
When the child shares I make a big deal out of it. Tell them how wonderful it is that they are sharing with plenty of clapping. They learn that sharing is not something to get upset about, but rather it is something fun that makes everyone happy.
I have a hard time bathing the child in the bathtub. I get a backache leaning over. When the baby is small enough, till they are about 1 or even more, I bath them in the kitchen sink.
When feeding baby I give the baby a spoon of their own so they learn how to use it early.
Don't hide the small arguements from the child. Do it without anger and let them see the resolution as well so that they can learn how do deal with negatives.
Remember that the child is not doing whatever it is that is making you angry "to you" or to be bad. Try to understand "why" they are doing it. For instance, if the child is throwing food on the floor they might be doing it cause it made a really neat sound. This doesn't mean that they are allowed to do it, but it will help with the way you deal with it without anger.
Say please and thank you, sorry and your welcome on a regular basis. You won't have to spend alot of time teaching your child this, they will pick it up from watching you.
I find that if they child has boundries they are much happier. They don't have the skills or the need to make decisions. However, flexibility is just as important. Sometimes, they need to feel that they have a say in what is going on.
Wednesday, October 11. 2006
If every piece of media had a backstory...
I was just tuning into DnB Podcast.com, specifically this awesome mix by Transient, which (if you follow the link) has an interesting album cover. This got me thinking, the mix itself does tell something of a story, and a story is implied by the cover itself.
So what if every piece of media has a backstory, or even better, given a back story? It wouldn't necessarily have to be public, but it would be an interesting way to get the creative juices flowing. Something to do on the ever-repeating public transit commute that I perform 6 times a week.
Pick a piece of media, and give it a backstory, or (if it is a spoken word podcast for instance) give it a front (i.e. a sketch or something similar).
What a great way to limber up ones creative muscles!
So what if every piece of media has a backstory, or even better, given a back story? It wouldn't necessarily have to be public, but it would be an interesting way to get the creative juices flowing. Something to do on the ever-repeating public transit commute that I perform 6 times a week.
Pick a piece of media, and give it a backstory, or (if it is a spoken word podcast for instance) give it a front (i.e. a sketch or something similar).
What a great way to limber up ones creative muscles!
Monday, October 9. 2006
Debugging your brain. Hacking the bad decisions and judgements of your brain.
I've been reading Mind Hacks, and Mind Performance Hacks lately. Awesome books. They have given me the chance to look, and change my brainstate—becoming my own metaprogrammer as it were. Just recently, I ran across a great blog entry titled: 10 Reasons people make bad decisions. I'll post the basics here, but you should really head over there for the full skinny.
If you have some understanding in the ways in which your brain makes flawed decisions, you can stop to think about your decisions, and potentially avoid making them in the future. The first step is to know what these flaws are.
If you have some understanding in the ways in which your brain makes flawed decisions, you can stop to think about your decisions, and potentially avoid making them in the future. The first step is to know what these flaws are.
- Sunk cost bias
This one is simple. People tend to put in more value into thing that they put a lot of time, energy and resources into. Think of that project where thousands upon thousands of dollars were invested upon something that ended up not working anyway. If someone would have killed the project at the $10,000 dollar mark, then $90,000 would have been spared, but how many of us can really be the ones to say "We're throwing in good money after bad here!" - Egocentricism
Egocentricism is something that everyone else has except you, right? The thing about egocentricism is that it is in our nature. There is really only one ego in our brains (usually) and ultimately, according to our brain, it is the only ego that counts. This can cause problems however, because we tend to see things happening to us as being more severe then they actually are. This is exemplified by an experiment described in the linked-to article:In a study conducted by Sukhwinder Shergill and colleagues at University College London, pairs of volunteers were connected to a device that allowed each of them to exert pressure on the other volunteers fingers. The researcher began by exerting a fixed amount of pressure on the first volunteers finger. The first volunteer was then asked to exert the same amount of pressure on the second volunteers finger. The second volunteer was then asked to exert the same amount of pressure on the first volunteers finger, and so on. Although volunteers tried to respond with equal force, they typically responded with about 40 percent more force than they had just experienced. Each time a volunteer was touched, he touched back harder, which led the other volunteer to touch back even harder.
- Confirmation Bias
This happens when our rational brains are short-circuted and we take an event and show it to be linked to our already established notions and opinions. This may be related to memes, and the tendency for memes to self-reinforce. - Overconfidence
Even if you are suffering from the deepest of self-esteem problems, chances are you are overconfident about some aspect of your life. For a good example, talk to any given driver out there "All the over drivers are idiots, but I know how to drive!" Programmers are similar in this regard. - Dysfunctional Competition
This is essentially the fact that our happiness tends to be measured relative to the other peoples happiness around us. We like to think that this is not true, but as this experiment shows:Max Bazerman from Harvard [who performed the experiment, said:] "When I ask people whether they would prefer a) $7 for themselves and for another person or b) $8 for themselves and $10 for the other person, people choose 'b.' However, when people are simply given 'a' or 'b,' 'a' makes them happier."
- The Endowment Effect
This is related to egocentricism. We tend to put more value on objects we already own, rather then their absolute value. In another experiment with mugs performed by Kahneman, Knetsch and Thaler, a random set of people were given mugs, and another random set of people asked to buy those mugs. The people who had mugs were only willing to part with them for $7, while the buyers were only willing to purchase them for $3. Now that's a seven dollar mug! - Availability Bias
This is the effect where we tend to see probability in terms of memorable events, rather then in terms of their absolute probability. Look at the amount of fear around, and energy spent on the War on Terrorism. It is more likely that you will die from a car crash, or even an STD then a terrorist attack. This also has an effect on the micro-scale of your personal relationships. Sometimes the most negative aspects of a relationship are the ones you remember the most. When this gets combined with confirmation bias, it can make for an insidious combination. - Conformity
This is an obvious one. Now I know that a lot of my frequent readers pride themselves as being non-conformist, but the kind of conformity being referred to here goes a little deeper. Buskers have known for years that if you seed your hat/guitar-case with some money, especially bills and higher denominational coins, people will generally give you more money. This is also called the "Restaurant effect", if you have 2 restaurants with one across the street from another, and one of them is seeded with people on its patio, and the other is not; the seeded restaurant will get more patrons. The effect of conformity is so subtle because most of us believe that we are somehow different, and immune from it, when we truly aren't. That means you Mr. or Miss non-conformist. - Illusion of Control
This is the effect that causes gamblers to bet more on crap shots that they role verus shots that other players role, even though the probabilities are exactly the same. We seem to think that we have more control over a situation then we actually do. - Attribution Error
We tend to think that people act and do things exclusively for our benefit, despite evidence to the contrary. That guy who cut you off in traffic quite likely didn't do it because he was an asshole, he was probably confused, a new driver, or even just distracted. In fact, maybe he is generally an asshole, but we tend to take his actions personally, as if he was cutting you off to be a prick at you, rather then because he is generally a thoughtless prick. The main effect here is that people tend to favor personality based explanations. It is similar to the old saw "Never attribute to malice what can be explained by stupidity." except, again it focuses on a character trait of the individual (stupidity) rather then what might be a more realistic explanation, such as a mistake, circumstances out of their control, or even other motivations.
(Page 1 of 1, totaling 6 entries)




