Thursday, 22 August 2013

Print alphabetical navigation list from an array

Print alphabetical navigation list from an array

I have an array of items and I am trying to generate an alphabetical
navigation for them.
A|B|C|D|E|F|G|H etc...
Apple
Apricot
Carrot
Camel
Dog
So I want to list every letter of the alphabet but only link the ones that
have matching items in the array.
So far I have:
$productArr = array('Apple','Apricot','Carrot','Camel','Dog');
$previous = null;
foreach(range('A','Z') as $alpha) {
$arrayCount = count($productArr);
for ($i=0; $i < $arrayCount; $i++) {
$firstLetter = $productArr[$i];
if ($firstLetter[0] == $alpha && $firstLetter[0] != $previous){
echo '<li><a href="#'.$alpha.'">'.$alpha.'</a></li>';
$previous = $alpha;
}elseif ($firstLetter[0] != $alpha && $alpha != $previous){
echo '<li>'.$alpha.'</li>';
$previous = $alpha;
}
}
}
It works fine up until the elseif, if you comment out the elseif it prints
the list of links as expected. Just need to work out how to print the rest
of the alphabet.
Any help as to where I'm going wrong would be appreciated.
Cheers

MYSQL MULTIPLE COUNT AND SUM

MYSQL MULTIPLE COUNT AND SUM

I hope this is possible in MYSQL, I am scripting with PHP.
I am trying to create multiple column on SUM of values and COUNT on table1
based on each month based with individual conditions and groupings. The
tables are already joined through the accountid. I have two tables
monthlyreport(table1) & planters(table2).
Desired Results is in table 1
MONTHLY REPORT (Table 1)
REPORTID|ACCOUNTID|COMPMONTH|SUMtoDATE|COUNTtoDATE|SUMcompDATE|COUNTcompDATE|
1 | 190 | JAN | 150 | 2 | 150 |
2 |
2 | 190 | FEB | 0 | 0 | 100 |
1 |
Planters (Table 2)
PlanterID | ACCOUNTID |PLANTER | SALARY | compDATE | toDATE |
1 | 190 | aaa | 100 | Jan-1-2013 | Jan-05-2013 |
2 | 190 | bbb | 50 | Jan-9-2013 | Jan-12-2013 |
3 | 190 | aaa | 100 | Feb-1-2013 | Mar-12-2013 |
4 | 190 | bbb | 0 | Mar-5-2013 | Mar-12-2013 |
A single query with inner join already works but if I run both I get
nothing because I can't seem to get the logic if it is possible.
This is what I have so far from stackoverflow but getting error. Wish
someone can refactor it or make it work.
SELECT *,
(
SELECT COUNT(planters.todate), SUM(planters.todate)
FROM monthlyreport
INNER JOIN planters ON monthlyreport.accountid = planters.accountid
WHERE monthlyreport.accountid = 190 AND MONTH(monthlyreport.compmonth) =
MONTH(planters.todate)
GROUP BY monthlyreport.mthreportid, month(planters.todate)
) AS count_1,
(
SELECT COUNT(planters.compdate), SUM(planters.compdate)
FROM monthlyreport
INNER JOIN planters ON monthlyreport.accountid = planters.accountid
WHERE monthlyreport.accountid = 190 AND MONTH(monthlyreport.compmonth) =
MONTH(planters.compdate)
GROUP BY monthlyreport.mthreportid, month(planters.compdate)
) AS count_2

Script to periodically check if a class has opened

Script to periodically check if a class has opened

Would anyone be able to help me generate a script which can either
periodically generate a search using the class search function
(website:SBCC Class - Lookup Search CRN: 36444) or look-up the correct
value from the Java/SQL (Not sure what they are using, sorry) table which
data is populated from?
Then based on the results of the search, I would to know whether or not
the class is CLOSED, OPEN, or WAITLISTED based on the result, and be
notified if the class is OPEN. Or if this is not possible I would be
interested in knowing why?
Again, any response is appreciated! Thanks.

Phonegap (3.0.0) debugging

Phonegap (3.0.0) debugging

I have small issues with debugging Phonegap application.
What I know:
I can upload application data to build.phonegap.com, build it, download
application to phone and then use debug.build.phonegap.com to debug
application, that's fine. That works for me.
What I want:
I would like to build phonegap application locally using Phonegap 3.0.0
CLI and Android SDK ("phonegap local run android") and then use weinre
debug server at debug.build.phonegap.com. Everything works fine except I
can't see it in debug.build.phonegap.com.
Why I want it:
It takes too much time to upload data, build it, download back and run.
Even when I can use phonegap CLI ("phonegap remote build android"). I
still have to use QR code, download it and install. Much better would be
using "phonegap local run android" (which installs app to phone
automatically) and then be able to use weinre debugger on
debug.build.phonegap.com
Why it is not working?
I think this is not working because build scripts in build.phonegap.com
are adding attribute into config.xml before building app. But I do not
know how to fill it with data.
I hope this is understandable. Thanks in advance, Martin

Hundreds of JBoss 5.1 System Threads WAITING forever

Hundreds of JBoss 5.1 System Threads WAITING forever

About 3 months ago we migrated to JBoss 5.1.0.GA and a few days after
testing we found several Out Of Memory Errors (OOME) in the logs of our
app.
Then I found an issue that described the cause as a bug in the JVM up to
version 7. We updated to version 7u25 and we haven't seen more OOME but
now I see an abnormally huge thread count: about 2k threads and of them
1.9k are daemon threads.
After checking in our monitoring tools I discovered that they are all
threads generated by the JBoss system thread pool (they are all named
JBoss System Threads(1)-XXXX). And here is the Stack Trace Details:
"JBoss System Threads(1)-1649" Id=130217 in WAITING on
lock=java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@a4d1d3
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
I have also checked in the tool for collection leaks and found the next
data that I think is somewhat related:

I have checked JBoss JIRA but haven't found something related.
Can someone point me what is going on?
UPDATE:
Here is the thread pool configuration in the jboss-service.xml
<!-- A Thread pool service -->
<mbean code="org.jboss.util.threadpool.BasicThreadPool"
name="jboss.system:service=ThreadPool">
<attribute name="Name">JBoss System Threads</attribute>
<attribute name="ThreadGroupName">System Threads</attribute>
<!-- How long a thread will live without any tasks in MS -->
<attribute name="KeepAliveTime">60000</attribute>
<!-- The max number of threads in the pool -->
<attribute name="MaximumPoolSize">3200</attribute>
<!-- The max number of tasks before the queue is full -->
<attribute name="MaximumQueueSize">3200</attribute>
<!-- The behavior of the pool when a task is added and the queue is
full.
abort - a RuntimeException is thrown
run - the calling thread executes the task
wait - the calling thread blocks until the queue has room
discard - the task is silently discarded without being run
discardOldest - check to see if a task is about to complete and enque
the new task if possible, else run the task in the calling thread
-->
<attribute name="BlockingMode">run</attribute>
</mbean>

Some E-mails are being rejected, do I need a DNS record for my default gateway?

Some E-mails are being rejected, do I need a DNS record for my default
gateway?

I have been seeing more of these types of bounceback messages (IP address
changed for example):
mail.test.com #550-Your message was rejected by this user and was not
delivered. 550-Reason: Your IP address [1.1.1.1] appears not to be an
email server. 550-Protection provided by: MagicMail version 1.3.5
(http://magicmail.linuxmagic.com) 550-For more information, please visit
the URL:
550-http://www.linuxmagic.com/best_practices/check_dynamic_reverse_dns.html
550-or contact your ISP or mail server operator. 550
ae9e5e74-0ad7-11e3-b831-0050569008a5 ##
We have all of the DNS records set up for our e-mail servers and smtp
outbound relay. Our MX record actually points back to our Barracuda
Spam/Virus Filter in front of our Exchange server. The IP address that the
message is referring to is our gateway address from our ISP.
What do I have to set up so that these messages are delivered? Do I set up
a fake MX record pointing to the default gateway? Add another A & PTR
record pointing to the default gateway? Is there something in our internal
configuration that could be incorrect? No records are set up for the
gateway address now, just the assigned IP addresses for each of the
outbound services. All servers are Windows based. Primary e-mail server is
Exchange 2007.

Storage Database Analysing, Input & Output table

Storage Database Analysing, Input & Output table

Storage System Database Analysing, about the Input & Output tables, what
is better, Keep the records of "IN" and "OUT" in the same table with type
"IN" or "OUT", or I have to separate it in tow tables one for "IN" and
another for "OUT" ?
Please any one have experience in this field to send me any suggestions or
references.