After my last post I thought it might be also helpful to publish how many open jira tickets I have to my skype status.
You can get each jira search result also as a rss feed. Your browser does indicate the link to the result as rss. This url might look something like:
http://jira.example.com/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?&&resolution=-1&assigneeSelect=specificuser&assignee=leo.buettiker&sorter/field=priority&sorter/order=DESC&tempMax=100&reset=true&decorator=none
To call this url, even if you have no valid session, you might add your user credentials at the end. This looks like:
&os_username=$username&os_password=$password
You could now use a xml or rss parser to interprete the returned feed. But for my result even that is too much, I only will count how many items in the feed are. The php snippet to do this will look like:
$jiraRss = file_get_contents($url);
$jiraCount = substr_count($jiraRss,'- <item>');
$jiraMessage = $jiraCount?" and $jiraCount open Jira Issues":"";
There might be a lot of other cool usecases you can simply implement (ticket you currently work on, Tickets closed int the last week, etc.). It's just a little bit sad that there is no REST API for Skype which would be make it easier to change the status between platforms.
You all know the troubles with overflowing inboxes. I'm a bit fan of Inbox Zero and I found a lot of ways to work fast with my mails. I did switch off signaling ingoing mails, I use a lot of filtering and a good folder structure.
But sometimes my own lazyiness get into my way. So I started to put "Inbox Zero" into my skype status if I get my box empty. But after some times I decided to automatised this message.
I do know that Patrice does automated Skype updates with his Mac. After a quick search I found out that on Windows Skype has a COM-Api and they even provide a little PHP Example. With PHP it is also pretty easy so to acess an IMAP inbox (MS Exchange also provide a IMAP access). So I wrote a quick script that updates my Skype-Message:
$mail = imap_open('{mail.example.com}INBOX','leo.buettiker', 'password');
// Create a Skype4COM object:
$skype = new COM("Skype4COM.Skype");
// Create a conversion object:
$convert = $skype->convert;
$convert->language = "en";
// Start the Skype client:
if (!$skype->client()->isRunning()) {
$skype->client()->start(true, true);
}
while(true) {
imap_check($mail);
$number = imap_num_msg($mail);
$skype->CurrentUserProfile()->MoodText=
"Leo has currently $number mails in his inbox";
sleep(5);
}
This does not only demonstrate how you can overcom your own lazyiness with open comunication and automated tools. It's in my point of view also a nice example what it's possible with PHP outside of the classical website rendering.
Ok, Mirko made me again losing a hell lot of time. He wrote a about his implementation of a quine in Ruby. Quines are just programmes that can replicated themselves without opening a file (also not itself, 'cause that would be too easy in PHP). As usual I had to try this in PHP myself. I found the article from Patrick Schneider very helpfully. He explains a quite cool approach with a base64-encoded-dna pretty clear. I just wrote the solution a bit shorter which brought it down to 159 chars (you have to have it all on one line):
<?=($dna='PD89KCRkbmE9JyonKT9zdHJfcmVwbGFjZShjaHIoNDIpLCAkZG5hLCBiYXNlNjRfZGVjb2RlKCRkbmEpKTonJz8+Cg==n')?
str_replace(chr(42), $dna, base64_decode($dna)):''?>
Unfortunately Mirko did not allow my copy-past solution (damn academics!). And for myself the solution with a generator is not too natural, as using another program to generate a quine is probably not like it was supposed to be. So with help of diff I tried to find my own solution:
php quine | diff -u quine -
I still nearly got a knot in the brain (much nicer in swiss german: "chnopf im chopf"). But after some trying I did had a solution which is with 113 characters even shorter:
<?=($a=array (
0 => '<?=($a=',
1 => ')?$a[0].var_export($a,1).$a[1]:"";',
))?$a[0].var_export($a,1).$a[1]:"";
By the way, as a nice start for the language of your choice you should look in the messy c2-wiki (although not all solution there might be work).
I hear and read the world scaling so often lately that I earnestly think about giving it a fixed field on my bullshit bingo card. As a lot of words on bullshit bingo, scaling is often misused.
After talking with Mirko and reading a lot of blogs I really think the world needs yet another one. So this article tries to try to kill 4 common misunderstandings of scaling, because scaling is not about…
[more after the jump]
Lots of functions listed on PHP.net- thank god!
[stumbled over
this on twitter]
I know, that's definitely old news. But still it's worth to mention that the
Zend Framework 1.5 is out since some weeks. It's a big jump from Zend 1.0 but also they have a lot new features in there (and probably some Zend Developers drink too much Java). They have also a new and cooler website for the project now.
In my point of View specialy the improvment in Zend MVC makes the framework now usable for companies with a lot of developers working on the same project (without patching the code over and over again).
The full list of improvments:
- New Zend_Form component with support for AJAX-enabled form elements
- New action and view helpers for automating and facilitating AJAX requests and alternate response formats
- Infocard, OpenID, and LDAP authentication adapters
- Support for complex Lucene searches, including fuzzy, date-range, and wildcard queries
- Support for Lucene 2.1 index file format
- Partial, Placeholder, Action, and Header view helpers for advanced view composition and rendering
- New Zend_Layout component for automating and facilitating site layouts
- UTF-8 support for PDF documents
- New Nirvanix, Technorati, and SlideShare web services
As I allready
mentioned I can't let my finger from coding contest. Unfortunately Bob found in a
comment in my blog more nasty stuff about links in html comments which makes parsing even harder.
I trimed my script again under the size of
the original script (ok, nearly the original), but I think if my regex skills would be a bit better, I could still squeeze some bytes out of it. But as I go finaly to holiday tomorow I will send my script to Paul and hope to get some points for the shortest script, as it will definitely not win any price for speed or beauty (did not wrote so ugly code since ages).
BTW: If you still trim you script, I brought up a
new testfile. You should still come up with the same 11 links. This
testfile is so ugly that my old konqueror is not able to parse it correct (but the comments are absolutly valid, according to
the documentation and
the validator).
Unfortunatly I can not resist if somebody brings up a coding contest. This time
Travis and
Paul wrote about
the coding contest of php architect at
planet-php. I did not invest a lot time into it, but still ways more then I planed.
The problem is that the ranking is once by speed and once by size of the script. Two parameters which usually not go well together. After having some great ideas for speeding up my code (even parallel processing, shared memory and
map-reduce came to my mind) I decide to let this race to others and fully concentrate to the size. I not even run benchmarks anymore.
Unfortunatly some nasty html special cases (whitespace, case independence, single- and double-quoting, various attributes and so on) blow my perfect sized script a bit. But with some nasty php method tricks it's hopfully still the shortest possible script that gets all valid cases.
Just to let you feel not to save, I wrote a
littel nasty html example that might break your own script. (You should get exactly
10 11 links out of it.)
First of all, be warned, this article has no pratical relevance. It even might guide you to bad code. But this week it just popped into my mind that I could use an array instead of a switch-case construct. So see how we can do this. This is the example for the switch in the php manual.
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
}
Now I'm able to implement this in a array, for that I put the code for every case statement in a arrayfield Afterwards I can access the field over the parameter and execute the code in it with eval.Here's the example: (Take care to not forget the semicolon in the code string)
$case[0] = "echo \"i equals 0\";";
$case[1] = "echo \"i equals 1\";";
$case[2] = "echo \"i equals 2\";";
eval($case[$i]);
Looks pretty, but what to do if you have to do the default statment. Nothing easier then that, we just have to look if eval goes ok and if not we do something after AND-short circuit:
eval($case[$i]) === false && print("default");"
The Pragmatic Programmer" sollte für jeden der mit Software Entwicklung zu tun hat Pflichtstoff werden. Warum ich so lang gehabt habe um dieses Buch zu lesen kann ich mir nur damit erklären das ich denn grössten Teil des Inhalts schon in Vorlesungen und in einem Vortrag von Andy Hunt gehört habe. Die Zusammenfassung des Vortrags, der einen grossen Teil des Buchs abdeckt, findet man in meinem Blog (
Teil1,
Teil2).
Andy Hunt und
Dave Thomas erklären auf nur knapp mehr als 250 Seiten alle wichtigen Paradigmas der modernen Software Entwicklung. Bei so wenig Seiten kann natürlich nicht immer ins Detail gegangen werden, gewisse Themen werden nur angeschnitten und müssen bei Interesse weiter vertieft werden.
Die Tipps wie man ein Projekt zu einem erfolgreichen Abschluss führen kann sind absolut unverzichtbar. "
The Pragmatic Programmer" muss man einfach gelesen haben.
Mein nächstes Buch aus dieser Reihe wird, sobald ich es von
Mirko endlich bekomme, "
My Job went to Serbia India".