Tag Archive for code

Find the Latitude and Longitude of a ZIP/Postcode using Google

function GetLatLong($postcode){
$myKey = 'Your_Google_API_Key_Here';
$URL = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=".$myKey;

$data = file($URL);
if($data){
$data = json_decode($data[0]);

$long = $data->Placemark[0]->Point->coordinates[0];
$lat = $data->Placemark[0]->Point->coordinates[1];

return array('Latitude'=>$lat,'Longitude'=>$long);

}else return false;

}

source

Dump a file to the terminal, starting at some line number

tail -n+99 foo.txt | more

source

Hide Myspace Comments

<style type="text/css">
table.friendsComments {
display: none;
visibility: hidden;
}
</style>

source

PHP (RegEx) Zip Code Validation

$string = "12345-1234";
if (preg_match('/^[0-9]{5}([- ]?[0-9]{4})?$/', $string)) {
echo "zip code checks out";
}

source

Find Verbose IDs in the DOM

var allTags = document.body.getElementsByTagName('*');
var ids = [];
var longId = 0;
for (var tg = 0; tg< allTags.length; tg++) {
var tag = allTags[tg];
if (tag.id) {
ids.push(tag.id);
if (tag.id.length > 30) longId++;
}
}
alert(longId + " out of " + ids.length + " IDs are too long.")

source

Code

<?php
$product_info_query = tep_db_query("select pd.products_name, p.products_model from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
$product_info = tep_db_fetch_array($product_info_query);
$products_name = $product_info['products_name'];
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE . " - " . $products_name; ?></title>

source

some Smart Code

    protected void setUp() throws Exception {
queue = new ClipBoardQueue();
}

source

Sample ASP Code

    public void testRefreshAddsCurrentElementAtTopAndRemovesLastContentIfClipBoardContentsAreChangedAndOfMaxSize() {
queue = mockClipBoardQueue(true, "New Content");

insertDummyValuesIntoQueue(2);
assertTrue(queue.refresh());

assertEquals(3, queue.getQueue().size());
assertEquals("New Content", queue.getQueue().getFirst());
}

source

Sample C# code new

public void testClipBoardContentsAreChangedWhenQueueIsEmptyContentProvided() {
assertTrue(queue.isClipBoardContentsChanged("New Content"));
}

source

Other Language Code

    public void testClipBoardContentsAreChangedWhenQueueIsEmptyContentProvided() {
assertTrue(queue.isClipBoardContentsChanged("New Content"));
}

source