Thursday, 22 August 2013

Case/Switch using Strings

Case/Switch using Strings

I have this weather script that and I'm trying to display a different
image for every weather condition (case), the image will also be different
if it's day or night.
Here is what I'm doing...
GETTING THE XML Info. into .PHP
<?php
$CapDCityANDState = "Atlanta, GA";
$url="https://www.google.com/ig/api?weather=$CapDCityANDState&hl=en&referrer=googlecalendar";
$xml = simplexml_load_file($url);
//print_r($xml);
//echo "Test: " . $xml->current_conditions->temp_f['data'];
$DayNow = date(D);
$DayTomorrow = date('D', strtotime('+1 day'));
$DayAfterTomorrow = date('D', strtotime('+2 day'));
$DayAfterAfterTomorrow = date('D', strtotime('+3 day'));
$CurrentTxt =
$xml->weather->current_conditions->condition->attributes()->data;
$CurrentTemp =
$xml->weather->current_conditions->temp_f->attributes()->data;
//echo $CurrentTemp[0];
echo("<BR><BR>");
$DayOneLow =
$xml->weather->forecast_conditions[0]->low->attributes()->data;
$DayOneHi =
$xml->weather->forecast_conditions[0]->high->attributes()->data;
$DayOneTxt =
$xml->weather->forecast_conditions[0]->condition->attributes()->data;
//echo $DayOneLow[0];
$DayTwoLow =
$xml->weather->forecast_conditions[1]->low->attributes()->data;
$DayTwoHi =
$xml->weather->forecast_conditions[1]->high->attributes()->data;
$DayTwoTxt =
$xml->weather->forecast_conditions[1]->condition->attributes()->data;
//echo $DayTwoLow[0];
$DayTriLow =
$xml->weather->forecast_conditions[2]->low->attributes()->data;
$DayTriHi =
$xml->weather->forecast_conditions[2]->high->attributes()->data;
$DayTriTxt =
$xml->weather->forecast_conditions[2]->condition->attributes()->data;
//echo $DayTriLow[0];
$DayFourLow =
$xml->weather->forecast_conditions[3]->low->attributes()->data;
$DayFourHi =
$xml->weather->forecast_conditions[3]->high->attributes()->data;
$DayFourTxt =
$xml->weather->forecast_conditions[3]->condition->attributes()->data;
//echo $DayFourLow[0];
?>
DISPLAY WEATHER FORCAST INFO.
<div>Currently: <?php echo $CurrentTemp[0]; ?>&deg; - <?php echo
$CurrentTxt[0]; ?> - H: <?php echo $DayOneHi[0]; ?>&deg; L: <?php echo
$DayOneLow[0]; ?>&deg; - Rest of the Day: <?php echo $DayOneTxt[0];
?></div>
<div><?php echo($DayTomorrow);?>: <?php echo $DayTwoHi[0];
?>&deg;/<?php echo $DayTwoLow[0]; ?>&deg; - <?php echo
$DayTwoTxt[0]; ?></div>
<div><?php echo($DayAfterTomorrow);?>: <?php echo
$DayTriHi[0]; ?>&deg;/<?php echo $DayTriLow[0]; ?>&deg; -
<?php echo $DayTriTxt[0]; ?></div>
<div><?php echo($DayAfterAfterTomorrow);?>: <?php echo
$DayFourHi[0]; ?>&deg;/<?php echo $DayFourLow[0]; ?>&deg; -
<?php echo $DayFourTxt[0]; ?></div>
<br>
FINDOUT IS IT DAY OR NITE CURRENTLY
<?php
$img = time() > $sunriseTime && time() < $sunsetTime ? 'day' : 'nite';
// $img <-- will say 'day' if it's day and 'nite' if its nite
?>
GET WHAT IMAGE TO SHOW DEPENDING IF IT'S DAY OR NITE AND ALSO GET THE
WEATHER CONDITION TEXT AND BASE THE IMAGE ON THOSE TWO FACTORS.
SHOW WHAT IMAGE NAME TO USE e.g. "32.png"
<?php echo($WeatherIMG); ?>
The image always shows "1.png" and that is wrong :(

how to select and sum in single sql query

how to select and sum in single sql query

Is it possible or another solution to sum and select multiple rows in
single sql query and print with while looping like that:
$query = mysql_query("SELECT SUM(Total), * FROM table");
while ($fetch = mysql_fetch_row($query)) {
echo $fetch[a];
echo $fetch[b];
echo $fetch[c];
}

Wednesday, 21 August 2013

How to split email address to retrieve name only?

How to split email address to retrieve name only?

With javascript, how do we remove the @gmail.com or @aol.com from a string
so that what only remains is the name?
var string = "johndoe@yahoo.com";
Will be just "johdoe"? I tried with split but it did not end well. thanks.

WMI Query to count number of messages in MSMQ poison queue

WMI Query to count number of messages in MSMQ poison queue

I can query the Win32_PerfFormattedData_msmq_MSMQQueue WMI object to get
the count of messages on an MSMQ queue as below, however this will return
a cumulative count of messages on the queue and it's subqueues (e.g.
poison and retry). Ideally I would like to get a count of messages on the
poison queue alone.
Is this possible using WMI?
Dim Locator
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Dim objs
Set Service = Locator.ConnectServer(".", "root\cimv2")
Set objs = Service.ExecQuery("SELECT MessagesinQueue " &_
"FROM Win32_PerfFormattedData_msmq_MSMQQueue " &_
"WHERE Name LIKE '%\\private$\\myqueue'")
For Each object In objs
WScript.Echo "Name: " & object.Name
WScript.Echo "MessageCount: " & object.MessagesInQueue
Next
Given the docs on subqueues this makes sense as they are just a partition
of the main physical queue, but is there any other WMI object or attribute
I can query to identify poison messages?
Subqueues are implicitly created local queues that are logical partitions
of a physical queue. Applications can use subqueues to group messages.
Subqueues are implicitly created when opened, are deleted when empty, and
have no open handles. Messages cannot be sent to a subqueue. Messages can
be received from subqueues, moved between the main queue and its subqueue,
or moved between a pair of sibling subqueues.
Subqueues do not have their own properties or state, but share the
properties and state of their parent queue. For example, a subqueue does
not have its own quota, access control list (ACL), or transactional type.

Table cells not fitting in row properly

Table cells not fitting in row properly

Preface: the table layout/old html is due to using this for a email
newsletter.
I'm in the process of building a simple navigation with a table. What I'm
looking for is a 650px wide table with a header row for a banner, and then
six cells equally spaced underneath that for the navigation links. Right
now, the second row has one really long cell with the "ABOUT" link, and
then the following five cells are way to the right of the table. It only
does this when I have an image in the top row.
Code:
<!DOCTYPE html>
<head>
<title></title>
<style>
#container {
background-color: #efefef;
width: 650px;
}
#row_nav {
width: 650px;
}
.nav_link {
width: 108px;
background-color: #AB2328;
}
</style>
</head>
<body>
<table id = "container" align="center">
<tr>
<td>
<a href="#"><img src="banner.jpg"/></a>
</td>
</tr>
<tr id = "row_nav">
<td class = "nav_link">
<a href="">ABOUT</a>
</td>
<td class = "nav_link">
<a href="">AGENDA</a>
</td>
<td class = "nav_link">
<a href="">SPEAKERS</a>
</td>
<td class = "nav_link">
<a href="">SPONSORS</a>
</td>
<td class = "nav_link">
<a href="">TRAVEL</a>
</td>
<td class = "nav_link">
<a href="">REGISTER</a>
</td>
</tr>
</table>
</body>
</html>
Any help would be much appreciated.

Shouldn't nHibernate ISession.BeginTransaction() fail when a transaction is already open?

Shouldn't nHibernate ISession.BeginTransaction() fail when a transaction
is already open?

I know these kinds of questions can lead to flame wars. Personally I'm a
huge fan of nHibernate and I realize no ORM is perfect. I'm just trying to
determine if there's a good reason for this I'm unaware of or if it's a
design flaw that exists because changing it would break existing code.
Here's the behavior I'm describing:
Assuming I have an existing ISession named session shouldn't the following
code throw an exception on the third line due to the fact that nHibernate
does not support nested transactions.
ITransaction tx = null;
tx = session.BeginTransaction();
tx = session.BeginTransaction();
If we assume that there are no other transactions open on the current
thread the first call to BeginTransaction() does indeed begin a
transaction. However the second merely returns the existing transaction.
It gives the impression that nested transactions are supported. Is this
bad nomenclature?
Would it make more sense to create two methods? One for grabbing an
existing transaction or creating one if none exists in situations where
the developer doesn't care and another method that specifically creates
new transactions and fails when it cannot?
This question is about nHibernate but perhaps this applies to Hibernate as
well.

Match a row as long as possible

Match a row as long as possible

I'm going to parse a position base file from a legacy system. Each column
in the file has a fixed column width and each row can maximum be 80 chars
long. The problem is that you don't know how long a row is. Sometime they
only have filled in the first five columns, and sometimes all columns are
used.
If I KNOW that all 80 chars where used, then I simple could do like this:
^\s*
(?<a>\w{3})
(?<b>[ \d]{2})
(?<c>[ 0-9a-fA-F]{2})
(?<d>.{20})
...
But the problem with this is that if the last columns is missing, the row
will not match. The last column can even be less number of chars then the
maximum of that column.
See example
Text to match a b c d
"AQM45A3A text " => AQM 45 A3 "A text " //group d has 9 chars instead
of 20
"AQM45F5" => AQM 45 F5 //group d is missing
"AQM4" => AQM 4 //group b has 1 char instead
of 2
"COM*A comment" => Comments do not match (all comments are prefixed
with COM*)
" " => Empty lines do not match
In this example, EACH row that I want to parse, is starting with AQM
How should I design the Regular Expression to match this?