tips posts

Easy to Remember, Yet Unique, Passwords

So we all know we're supposed to have a different password for every site we go to, but of course no one does that.  Instead you end up using the same password for everything because its easier to remember.  The problems occur when your favorite website, knittin-for-kittens.org, gets hacked and your password stolen, and its the same password you use for your bank account.

password.jpgWhat you need is a password scheme that lets you use a different password for every site you go to, so even if one gets stolen, it won't comproise all your other sites.

Here's the system I use:

Chose a random, nonsense "base" with both numbers and letters. Include at least one capital letter.  For example:  zh2Ms
This is just something you will have to dedicate to memory.  If you base it on a phrase, that can help.  Example: zebra have 2 Many stripes = zh2Ms

Next, add on the name of the site or service you are using.  For example...

gmail:         zh2Msgmail
facebook:   zh2Msfacebook
bank:          zh2Msbank

and so on.  Now you have unique passwords for every site you use, but you will always be able to remember them.

PS:  for the best security, you should really be using lastpass!  It's wonderful and free.
 

Draw a Box Around a Coordinate In Google Maps Based on Miles or Kilometers

Attached File(s): 

This post explains how, given latitude and longitude coordinates in Google Maps (specifically, in the Static API), how one can draw a bounding box around them, based on a distance in either miles or kilometers.

gmap_bounding.pngLet's say you already know the lat/long of a particular point on the map, and now you want to draw a box around it, or maybe you just need to know the lat/long coordinates of another point, so many km or miles away?  Well, this is the script for you!

Based on a script retrieved from here:
http://www.sitepoint.com/forums/showthread.php?656315-adding-distance-gps-coordinates-get-bounding-box

The trick is that Google Maps wants you to provide it with the lat/long coordinates for each corner of the box.  After several hours of searching, I finally found a script which I was able to modify to give me what I needed.

Simply download the script linked at the top of the page, and then use the following code to create the image you see here. 

Enjoy!


    $lat = -33.872986011907216;
    $lng = 150.90904516601563;

    // Create the static map api image.
    $static_maps_url = "http://maps.googleapis.com/maps/api/staticmap";
    $static_maps_url .= "?center=$lat,$lng";
    $static_maps_url .= "&zoom=15";
    $static_maps_url .= "&size=300x300";
    $static_maps_url .= "&maptype=roadmap";
    $static_maps_url .= "&sensor=false";
    $static_maps_url .= "&markers=color:blue|$lat,$lng";

    // Figure out the corners of a box surrounding our lat/lng.
    $d = 0.3;  // distance
    $path_top_right = bpot_getDueCoords($lat, $lng, 45, $d);
    $path_bottom_right = bpot_getDueCoords($lat, $lng, 135, $d);
    $path_bottom_left = bpot_getDueCoords($lat, $lng, 225, $d);
    $path_top_left = bpot_getDueCoords($lat, $lng, 315, $d);
   
    $static_maps_url .= "&path=color:334433|weight:5|fillcolor:0xFFFF0033|";
    $static_maps_url .= "$path_top_left|$path_top_right|$path_bottom_right|";
    $static_maps_url .= "$path_bottom_left|$path_top_left";
     
    // Now, draw the image from Google Maps API!
    print "<img src='$static_maps_url'>";


 

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Android Tip: Preferences - Easier Than Using a Database - With Code Sample!

Attached File(s): 

If you have done any programming for an Android phone, you've probably already used (or at least heard of) Android's built-in database option of SQLite.  SQLite is a fine system, but it can be cumbersome to work with, especially if you only need to store a few values. 

samsung-omnia-hd-android.jpgEnter your new best friend: Preferences.

Think of "Preferences" as a way to save data (like Strings) outside of your application.  It's like a database in that way, but it is much easier to put data in and get data out.  If you build a Preferences Activity at some point, then it will actually be using this very system-- but that's another blog post.

I have included my own class for working with Preferences.  It is linked at the top of the post.  To use it, instantiate a Prefs object like so:

Prefs prefs = new Prefs(context);
// Prefs prefs = new Prefs(this) will work 
// if you are within an Activity

Now, to store a String value, all you have to do is this:

String mUserNameString = "rpeacock";
prefs.setPreference("username", mUserNameString);

To retrieve that value later, even after the app has closed and restarted, all you have to do is this:

String temp = prefs.getPreference("username");

Isn't that easy?  More to the point, isn't that much easier than creating an SQLite object, constructing a query, executing the query, then closing the connection?  That's why I use Preferences everywhere I can.  It's also great for accessing values between Activities, services, etc.

The code I attached only does Strings, but you can easily extend it to work with any value.  Enjoy!

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Is Your Laptop Overheating?

Recently, my laptop started running hotter and hotter, to the point that it would shut itself down out of protection.  Speedfan reported my core temperature (under load) above 100C (the temperature of boiling water)!  It idled around 60 - 70C.  I almost went out a bought a new laptop, assuming my processor or power supply or something must be breaking down.

laptopfire.jpgWell, I'm glad I didn't, because I fixed it with one simple trick after some googling.  All you need to do is break out your vacuum cleaner, and clear the dust from the laptop's cooling system.

On most laptops, that means two points:  an intake vent, and an exhaust vent.  The idea is that air is sucked into the laptop through the intake vent, passes over your hot components, and then blows out of the exhaust vent, cooling everything down in the process.  This is all done with 1 or 2 fans, which can get very dusty over time.

It's that dust that causes the laptop to overheat.  It chokes the fans and creates a blanket over your components.

So, just take your vacuum cleaner's hose attachment and go over both vents really well.  The intake vent is probably on the bottom of the laptop, and the exhaust is probably on the side or back. On some laptops, to really get rid of all the dust, you might have to take the cover off and blow out the fans/vents with compressed air.  I didn't have to with mine, though.

After doing this, my laptop idles around 52-54C, and under load it gets to around 60-65C.  It's still a little hotter than I want it to be, but that's nothing compared to 100C!

So if you've got a dangerously overheating laptop (use Speedfan to check) then give this tip a try.  If it doesn't work, it probably means you have a more serious-- and more expensive-- problem.

 

Dropbox and Programming - A Match Made in Heaven

For those that don't know, Dropbox is a free service which lets you share a folder across multiple computers, even with different OSes like Mac, Windows, and Linux.  It's great for keeping all your personal files with you on both your work and home PC (without the need for a USB drive).  But where it really shines for me is when it comes to programming.

Dropbox-Review-2.jpgProgramming from multiple computers is always a bit of a pain.  What I normally do is I keep all my files on a USB drive, and just have to remember to carry it with me every where I go.  I'm always worried about breaking or losing it, so I have to back it up like crazy.

Another option is to use a version control system like Subversion or Git.  They work (usually), but you've got to remember to commit changes before moving to another computer.  For newbies they can be complicated to set up, and might be overkill for smaller one-man projects. Plus my IDE for Android development, Eclipse, just doesn't want to play nice with Subversion.

Enter Dropbox, my new hero.

Using Synergy With a Null Modem Cable

If you've never heard of Synergy, check out there website here.  In a nutshell, it's a program you run on two computers, which lets you use the keyboard and mouse of one to control the other.  Think of it a little bit like a KVM switch in software.  The connection is made over your network or the Internet.  To switch machines you just slide your mouse off the side of one screen and onto another, as if you just had a second monitor set up.

null-modem-cable.jpgRecently at my day job, I used Synergy to connect my main work computer to a spare computer I set on my desk but did not want to make room for another keyboard and mouse.  I also did not want to connect our company network to the spare computer, for security reasons.  Now, I could have just used a cross-over ethernet cable, but did not have a spare ethernet port on my main computer.

Enter my savior: an ancient serial Null Modem cable.

In the good old days, these little serial cables were used to connect two computers together at a relatively low speed for file transfers and the like.  And if you happen to have one laying around (possible with an extra "null modem" block attached, possibly not), then this guide will help you set up two Windows computers to use it to work with Synergy.

Tips: Creating Web Sites for Mobile Phones

I've recently learned a few technical tips you should use when creating web sites for mobile devices (like the iPhone, Android, etc) and though I'd share them all in one place.

9658-bbcskyfirecopy.jpg#1: Size matters

This should be obvious, I guess, but you're dealing with a smaller screen.  Unfortunately, you really have no idea what the screen size is, so you have to low-ball it.  Various sources on the Internet agree that you shouldn't have images, tables, divs, etc. any wider than 240 pixelsMaybe 320, but you're pushing it, mister.  Of course, that could change as time goes on, but at the time of this writing, 240px seems to be the most widely accepted width that fits on the most screens.

Also, don't forget to place this at the top of your page:

<meta name='viewport' 
   content='initial-scale=1.0, user-scalable=no' />

This will cause the device to be zoomed-in on your content, and not let the user zoom out any more.  Just try it out and you'll see what I mean.

IE Can Only Handle 31 Stylesheets -- Thanks IE!

Yes, our old friend Internet Explorer is at it again to make our lives as web developers miserable.  Not many know this, but in IE, a single web page can only reference at most 31 <link>'d CSS stylesheets. For hand-coded pages, this probably isn't a problem.  But when you start using larger CMS systems and applications, like Drupal, you can very quickly run into the 31 stylesheet limit.  This happens in currently all versions of IE, including IE 8.

ie_sucks_sm-300x225.pngMost of the time this problem presents itself, the web developer believes he or she is going insane.  Your site looks beautiful in FireFox and Chrome, but in IE everything is off: some things are positioned weird, fonts are the wrong size, etc.  And IE doesn't warn you or let you know this is happening in any way, so you are left to go silently mad trying to figure out what the problem is.

There are a couple possible solutions:

  • Combine stylesheets into single, large files.  This may not always be practical or very organized, but hey, you've got to do what you've got to do.
  • Use @import instead of <link>
    • For example:
      <style>
      @import url('a.css');
      </style>
    • IE seems to be okay with this, and will allow more than 31.  However, @import isn't as great, performance-wise, as <link>.  Also, it may cause stylesheets to be loaded out of order, which can cause JavaScript problems.
  • If you are using Drupal, you can try the modules http://drupal.org/project/ie_css_optimizer or http://drupal.org/project/unlimited_css to get around the IE problem.

 Let's hope that the next version of IE lifts this bizzare restriction (but I'm not holding my breath).

Oracle_query() and Other Oracle Convenience Functions

Attached File(s): 

If you're used to using MySQL with PHP, you already know of the simple and easy to use mysql_query(), mysql_fetch_object(), mysql_affected_rows() and so forth functions.  Well, if you've ever dipped your toes into the tepid waters of Oracle, you know that it lacks the friendly PHP functions that MySQL has.  So, I created a set of convenience functions designed to mirror the MySQL ones.

Just download the attached file at the top, and use it like so:

<?php
  
  include_once("oracle_common_functions.php");

  oracle_connect($username, $pass, $host, "TEST");
  $res = oracle_query(" SELECT * FROM $table_name ") or echo(oracle_error());
  while ($cur = oracle_fetch_array($res)) {
    var_dump($cur);
  }  
  
  oracle_close();
  
?>

Just remember that to use any of this, you also need PHP to be compiled with the necessary oci libraries.

Complete list of functions in the file:

oracle_connect()
oracle_query()
oracle_fetch_array()
oracle_fetch_object()
oracle_affected_rows()
oracle_close()
oracle_error()
oracle_errno()
oracle_escape_string()

Enjoy!

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Meet My Friend, Mr. Curly Brace

The curly brace (also known as the curly bracket) is a fairly powerful tool in PHP.  In a nutshell, it lets you specify the name of a variable in a string.  Why is that so important?  Because what if you want to specify a member variable to an object in another variable?  Maybe an example would elucidate the problem...

Let's say you want to compare apples to oranges in a standard object...

$obj = new stdClass();
$obj->apples[] = "Granny";
$obj->apples[] = "Red";
$obj->apples[] = "Bad";

$obj->oranges[] = "Navel";
$obj->oranges[] = "Tangerine";

Now, let's say that you need to access either the apples array or the oranges array based on some other variable, $fruit

Syndicate content