Archive for the ‘Uncategorized’ Category

Using adb to play a game for you on an Android device.

May 17th, 2012 by joey | No Comments | Filed in Uncategorized

I recently flashed my Kindle Fire with the latest CyanogenMod 9 image using the awesome Kindle Fire Utility.  This put Android Ice Cream Sandwhich on my Kindle Fire.

I play a game “Defender II” which is a lot of fun.  But, you have to play it ALOT to level up and upgrade all your weapons.  (Which takes a LONG time).

I knew about Androids Debug Bridge which you use to root most android devices.  And so I did a quick google search to see if you could simulate touches on the screen with it.

YOU CAN!  So, I wrote a little php page that uses some javascript, jQuery, and ajax to send the right inputs to my kindle fire to play the game for me.  It doesn’t do any reading from the device, just screen touches, so it obviously doesn’t play the game very well.  But, it provides me with Defender II cash, and experience points every time it plays for me.  So, if I let it run for a few days, I should be able to get the next 75000 point Multi Arrow upgrade!



While somewhat of a useless excercise I did learn alot about the adb  and a little more bout Android.

The code to do this yourself is below:

(send_input.php)

<?php
if (!empty($_GET['action'])) {
    $commands = array();
    if ($_GET['action'] == 'click') {
        //Up
        $commands[] = "sendevent /dev/input/event1 3 48 0";
        $commands[] = "sendevent /dev/input/event1 0 2 0";
        $commands[] = "sendevent /dev/input/event1 0 0 0";

        //Down
        $commands[] = "sendevent /dev/input/event1 3 57 0";
        $commands[] = "sendevent /dev/input/event1 3 53 " . $_GET['y'];
        $commands[] = "sendevent /dev/input/event1 3 54 " . $_GET['x'];
        $commands[] = "sendevent /dev/input/event1 3 48 1";
        $commands[] = "sendevent /dev/input/event1 0 2 0";
        $commands[] = "sendevent /dev/input/event1 0 0 0";

        //Up
        $commands[] = "sendevent /dev/input/event1 3 48 0";
        $commands[] = "sendevent /dev/input/event1 0 2 0";
        $commands[] = "sendevent /dev/input/event1 0 0 0";
    } elseif ($_GET['action'] == 'move') {
        $commands[] = "sendevent /dev/input/event1 3 57 0";
        $commands[] = "sendevent /dev/input/event1 3 53 " . $_GET['y'];
        $commands[] = "sendevent /dev/input/event1 3 54 " . $_GET['x'];
        $commands[] = "sendevent /dev/input/event1 3 48 1";
        $commands[] = "sendevent /dev/input/event1 0 2 0";
        $commands[] = "sendevent /dev/input/event1 0 0 0";
    } elseif ($_GET['action'] == 'up') {
        $commands[] = "sendevent /dev/input/event1 3 48 0";
        $commands[] = "sendevent /dev/input/event1 0 2 0";
        $commands[] = "sendevent /dev/input/event1 0 0 0";
    }

    system('adb shell ' . implode(";", $commands) . ";");
} else {

    ?>
<link rel="stylesheet" type="text/css"
      href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
<script>
    jQuery(function () {
        jQuery('[x]').click(function () {
            var $this = jQuery(this);
            jQuery('[name=x]').val($this.attr('x'));
            jQuery('[name=y]').val($this.attr('y'));
            jQuery('[name=action]').val(jQuery(this).attr('name'));
        });

        jQuery('[type=button]').click(function () {
            jQuery('[name=action]').val(jQuery(this).attr('name'));
            jQuery('form').submit();
        });

        jQuery('form').submit(
            function () {
                var $this = jQuery(this);
                jQuery.ajax('send_input.php?' + $this.serialize(), {async: false});
                return false;
            }
        )    ;



    });

    function play(){
        jQuery('[value=Top]').click();
        jQuery('[value=Top]').click();
        jQuery('[value=MiddleTop]').click();
        jQuery('[value=Middle]').click();
        jQuery('[value=MiddleBottom]').click();
        jQuery('[value=MiddleBottom]').click();
        jQuery('[value=Top]').click();
        jQuery('[value=Top]').click();
        jQuery('[value=MiddleTop]').click();
        jQuery('[value=Middle]').click();
        jQuery('[value=MiddleBottom]').click();
        jQuery('[value=MiddleBottom]').click();
        jQuery('[name=up]').click();
        jQuery('[value=AdClose]').click();
        jQuery('[value=ContinueButton]').click();
        setTimeout(play, 1000);
    }

</script>
<form method="get">
    X: <input type="text" name="x" value="<?=!empty($_GET['x']) ? $_GET['x'] : 0 ?>">
    <br/>
    Y: <input type="text" name="y" value="<?=!empty($_GET['y']) ? $_GET['y'] : 0 ?>">
    <br/>
    Action: <input type="text" name="action" value="<?=!empty($_GET['action']) ? $_GET['action'] : '' ?>">
    <br/>

    <input type="button" name="click" value="Down">
    <input type="button" name="move" value="Move">
    <input type="button" name="up" value="Up">
    <br/>
    <input type="button" name="move" value="Top" x="3500" y="2100">
    <input type="button" name="move" value="MiddleTop" x="3500" y="1575">
    <input type="button" name="move" value="Middle" x="3500" y="1050">
    <input type="button" name="move" value="MiddleBottom" x="3500" y="525">

    <input type="button" name="move" value="Bottom" x="3500" y="0">
    <br/>
    <input type="button" name="click" value="ContinueButton" x="3500" y="2100">
    <input type="button" name="click" value="AdClose" x="3500" y="1000">
</form>
    <input type="button" name="start" value="Auto Play" onclick="play();"/>
<?

}
?>

If you use PHP, you should read this.

March 13th, 2012 by joey | No Comments | Filed in Uncategorized

I like dynamic languages.  They are flexible, allowing you to do things quickly that could not be done, or are impossible in strongly typed languages.  Even many strongly typed languages (like Java) bend their strongly typed rules to achieve things you can do readily in other languages.

So what’s the downside?  IDE’s have a hard time performing auto-complete and embedded help because it doesn’t always know what type a variable is.

Enter….  Type Hinting!

I use it, and love it.  While I greatly like Dynamic Languages for their flexibility.  I really like having the option to enforce typing when I want.  Yay for PHP!!!

 

 

Why you CANNOT re-use many modern Head Bolts

November 27th, 2011 by joey | No Comments | Filed in Uncategorized

Recently I replaced the head gasket on a 1999 Mitsubishi Mirage with the 1.5L SOHC.  While torquing down the head bolts according the the tighten, loosen, tighten, turn another 180 degree procedure two of the bolts got very loose while turning the additional 180 degrees.  I was a little dumb struck and couldn’t explain it.  I decided to carry on anyways.

When I started the car for the first time it was spewing out white smoke (burned antifreeze).  It was kind of cool, the smoke clung to the ground like a creepy low fog…

I was bummed.  Here I had spent several days changing the head gasket and it wasn’t sealing right.  I decided perhaps I just hadn’t tightened the bolts properly because I had used new bolts, we had the head machined flat, and the block was steel so I wasn’t too worried about that warping.

I got online and did some research hoping for a simpler alternate torquing procedure.  What I found instead is an explanation of “Torque To Yield” head bolts.

If you do much work on cars you may have noticed that newer head bolts (starting around the mid 80′s I think?)  are much smaller.  These are “TTY” bolts.  These are bolts that when properly torqued are tightened past their “yeild point“.  When a bolt is tightened beyond it’s yeild point it is stretched in a way that it WILL NOT return to it’s previous shape.  Most materials have an elastic region where as you stretch it it will always return to it’s normal shape and then a yeild point (which the the absolute most you can stretch it and it still retain it’s original shape), followed by a “plastic region“.  In this plastic region the metal still stretches but it will NEVER return to it’s original dimensions.

What this means is that unlike older head bolts the head bolt can only be tightened ONCE.  It will never return to it’s original shape.

So why do cars use these use once head bolts?  The answer is simple, it provides more even and constant head to block pressure.  You see, when a bolt is stretched in it’s elastic range, the pressure the bolt maintains on the surface goes up VERY fast as you tighten it more (notice the STEEP incline of the red line between the beginning the the point marked with the 2).  However, when you get into the plastic region the pressure on the surface the bolt exhibits changes much less as the bolt is stretched while the engine heats and cools, etc (from mark 2 to mark 3)…

The reason my head bolts failed, is that when I took them to 14 ft lbs I over tightened them a little (my torque wrench is not well calibrated), and when I put the bolts in the plastic region by tightening them another 180 degrees I passed the “Ultimate Strength” (see image below, it’s where the red line peaks). When I passed that point, the bolt began to hold LESS as it stretched instead of more, and the torque of the bolt declined until at the end of the red line it broke.

Back to the car…  I wasn’t sure last night exactly why the bolts got loose after tightening but it felt just like a stripped bolt.  I figured would try to tighten them, and if it broke off, I would use an easy out, and if it is stripped I’ll have to take it apart to repair the threads.  I tightened the bolt another 360 degrees (approx) and SNAP the bolt broke.

It was an easy job with an easy out, and a McGuiver style electro-magnet to pull out the broken part of the stud. (Usually when a bolt breaks, it spins right out of it’s hole because the pressure is removed, as was the case here.).  Tomorrow I’ll order a new set of head bolts, and use my friend’s borrowed craftsman beam torque wrench (beam torque wrenches are generally more accurate the click style torque wrenches) to install the new head bolts and hopefully the car will be fixed (fingers crossed and prayers said).

So the basics of all of this…  If the head bolts never surpasses their yield point you should be able to re-use them as long as the threads stay in good condition. However, if the bolt ever surpasses it’s yield point, it needs to be discarded and replaced.  So, big giant head bolts, may be safe to re-use (unless the engine over heated in which case it is more likely the bolt was stretched beyond it’s yield point), smaller diameter head bolts (especially ones with a torque procedure that has you tighten, loosen, tighten, turn N degrees) should NEVER be re-used.

(Guide to reading graph) In Engineering terms the “Strain” on a material is the distance it is stretched, while the “Stress” can in very simple terms be called the force the bolt exerts on the materials it is holding.  So as you can see, stress shoots upwards EXTREMELY fast while in the elastic region (usually linear), and then enters the plastic region where as the bolt stretches the force stays much more constant, but once the ultimate strength is surpassed the stress and force decline until the bolt breaks.

Tags: , ,

Why A/C Units Need a proper P-Trap, and how to build one.

August 20th, 2011 by joey | 1 Comment | Filed in Uncategorized

Recently, my wife and I returned from a week long vacation.  When we arrived home we immediatly turned the A/C back down (we had set it high since we weren’t going to be home).  Later on that night, we were eating dinner, when I hear water pouring in one of our bathrooms, I go look, and discover that water is POURING in through the roof.   The only thing above the roof that had water was the A/C.  As I thought about this, I realized what the problem was… We didn’t have a P-Trap on our A/C unit!!!!!

What is a P-Trap you say?

A P-Trap serves a very important purpose on an A/C unit.  See, when moist air hits something cold, the water condenses out of the air and collects on the cold surface.  Air Conditioning units pull A LOT of water out of the air.  That is why in the summer, your car drips water. All air conditioners have a special drain for this condensation.

Some A/C units (like ours)  have a negative air pressure inside them when running.  What this means, is that the air is being sucked through the air conditioner instead of blown through, and so the inside of the air conditioner is at a lower pressure than the outside air.  This presents a problem for the condensation drain…  Since the Air Conditioner is at a negative pressure relative to the outside air, the outside air will rush into the air conditioner through any openings (the condensation drain, is an opening).  On our A/C the air rushing in through the condensation drain was preventing the water from exiting through the drain.  So water was building up in our A/C unit and when it would turn off “Woosh…”  All that water would pour out of any hole it could find!  Since we hadn’t run the A/C in a week when we got home, it ran for an hour or two straight.  During which time it collected A LOT of water inside.  When it shut off….  Whooosh…  Water came pouring out of places it never had before causing it to flow out of the roof in our bathroom.

So…  What is a P-Trap.  A P-Trap is NOTHING more than a properly shaped piece of pipe…  No moving parts, just the proper shape so gravity does the work for us.   See below for an image of a sink P-Trap (which works the same way).

See, water won’t flow up-hill…  So the 180 degree turn in the drain causes water to get “trapped” in the bottom of the P-Trap.  Water can still flow, because when water goes down the drain, it pushes the water on the other side out.  On a Sink the purpose of the P-Trap is to keep nasty sewer smells from coming up the drain. (you know what an outhouse / latrine smells like?  Well this little 180 degree bend is the only thing that keeps your kitchen from smelling that way.).

The same thing applies to our air conditioner, but in our case, the purpose of the P-Trap is to prevent outside air from being drawn through the A/C unit.  The weight of the water in the trap is enough to prevent this, while still allowing condensation to flow freely.

Another key component of a P-Trap is an air vent…  The Air vent prevents the drain that comes after the P-Trap from siphoning the water in the trap out.

 

Here is our finished product.  The important dimensions for a P-Trap are…  That the exit point of the trap is 4 to 6 inches lower than the entrance point.  The overall height of the trap should be 8 to 12 inches, and the distance between the two sides of the trap should be 4 to 6 inches.  But, honestly, these things are fool proof, the only really important thing is that the exit is at least 3″ below the entrance, and the 180 degree turn at the bottom sits at least 3″ below the exit as well.  This simple piece of plumbing fixed our problem perfectly, and condensation now runs freely when the A/C is running instead of Ga-Whooooshing….  When it turns off.

Special Thanks to Bill McMain, my good friend who is conveniently a HVAC engineer, and enjoys answering my questions about A/C magic…

 

Consumer Debt Free!!!

February 28th, 2011 by joey | 4 Comments | Filed in Uncategorized

Using our 2010 Tax Return, my wife and I were able to completly pay off all of our consumer debt.  We now only have mortgage payments.  Everything else, including cars, is 100% paid for!!!

Yay!!!  Let me tell you, it feels good!

The Forgotten Marquee Tag!!

February 7th, 2011 by joey | 4 Comments | Filed in Uncategorized

A long time ago, in a galaxy not that far away.  A world called Earth was exploring a new technology called “The Internet”.  People all over downloaded a primitive browser called “Netscape” in order to experience the Internet.  Many people joined a cult of JavaScript programmers that wanted to do “cute” things in the browser.  Eventually this cult gained power, and some of these “cute” things were given away freely to all instead of requiring membership in the cult of javascript programmers.

And thus was born!  The Marquee tag…

The Marquee tag is a long forgotten html tag that creates a scrolling marquee.

Like this:

This is the coolest blog Ever!!!

Amazing Caterpillar Crossing! Stops traffic for 20 minutes in South Africa!

October 26th, 2010 by joey | 2 Comments | Filed in Uncategorized

This is the moment a group of tiny caterpillars formed an incredible 17ft long convoy to cross a road in the Kruger National Park.

Some 136 caterpillars made the single line and wriggled top-to-toe across the road, linked by a thin silk thread which set their path.

And their safety-in-numbers approach had the desired effect as the slow-moving convoy was easily seen by motorists, who were held up for 20 minutes as it made its way across.

Bumper to bumper: This slow moving convoy of migrating caterpillars was spotted in the Kruger National Park by Jamie Rooney, from High Wycombe, Bucks

The spectacle was captured on camera by British tourist Jamie Rooney, who was visiting the famous Kruger National Park in South Africa.

Jamie, from High Wycombe, Bucks, was in a Jeep full of tourists when their driver slammed the brakes just inches from the crawling caterpillars.

Jamie, 38, who works in website sales, said: “It was an incredible sight.

‘We were out driving in Kruger National Park for a safari, when all of a sudden the driver shouted out and slammed on his brakes.’

‘He managed to stop just in time in front of this amazing trail of caterpillars, which was stretching across the road.’

‘Conservation is a massive deal in South Africa and the idea is that if there is any living creature in the road you have to wait patiently until it is safely across.’

‘We got out to get a closer look and counted 136 caterpillars in convoy, all moving together across the track.’

‘They were following a very, very thin silk thread on the ground and it took them about 20 minutes to get across the road safely.’

‘Our guide had never seen it before, but he’d heard about it and explained they were migrating into the bush where they would disperse.’

‘It’s like the mass migration of bigger animals like wildebeest, but on a different scale and pace.’

‘When they arrive in the bush, they turn into chrysalis and then butterflies.’

‘It’s a rare sight. It was an absolute joy to watch and a great experience to be able to get down close and see it first hand.’

This incredible convoy is the ultimate commuter train – a trail of tiny caterpillars heading off into the bush. An amazing 136 caterpillars wriggled top-to-toe across
a road on their migratory route in Kruger National Park, South Africa.

McDonalds Happy Meal – The Zombie Burger…

October 25th, 2010 by joey | No Comments | Filed in Uncategorized

Interesting sites and stories float around the Dev room here at work almost daily.  Last week the story of McDonalds Burger’s not decomposing was the hot topic…

Check out this site: http://articles.mercola.com/sites/articles/archive/2010/10/25/mcdonalds-happy-meal-shows-no-sign-of-decomposing.aspx

It’s crazy.  But true…

Why is your car insurance so high? Perhaps it’s your C.L.U.E

September 9th, 2010 by joey | No Comments | Filed in Uncategorized

My good friend Jacob Allred posted this article that sheds some light on how your insurance claims can increase the cost of your insurance.

Here it is:  http://www.jacoballred.com/money/find-out-why-your-car-insurance-is-so-high/

test

August 18th, 2010 by joey | 1 Comment | Filed in Uncategorized

test