Go to the navigation

elblogg

»php

Flickr shortcode plugin for WordPress

Earlier this week I wrote about how you can add a shortcode to the functions.php to make it easier to use Creative Commons images on your blog, while always remembering to put in the correct attribution.

Adding this to your theme has some drawbacks. The most important one is that you’ll have to do it all over when you change the theme, another is that you have to add the flickr api key directly into the code.

That’s why I have just made it into a wordpress plugin. This means you just need to download the package, extract it into the plugins folder, and then use the “El Flickr” menu entry to add the flickr api key.

I have changed the flickr shortcode to elflickr, so there should be less possibility for conflict with other plugins. You chan also change the shortcode to whatever you want (including flickr) from the configuration page.

I’ve also added another feature. Lets say you need a HDR picture of Bergen, but don’t care too much which one is used, what if you could add the picture without going to flickr to look it up? The question is of course rhetorical, because now you can.

[elflickr search="HDR Bergen from Fløien"]

yields the picture in the beginning of this article. The result of the search is stored, so you don’t need to worry that the search results will change over time. It also limits the search to Creative Commons licensed pictures.

[elflickr search="Tilt shift bergen city"]
old houses in Bergen by Julia ( kroolik on flickr)

I have a lot of ideas for this plugin, the release is numbered 0.0.2, and there’s a lot of room for improvements. For instance I will incorporate the gallery into the plugin, which currently is implemented in my theme.

Download el_flickr 0.0.2


If your blog is hosted on my server, I will install it for you if you ask me to.

The plugin just generates the HTML code, you need to style it using your stylesheet, see the flickr shortcode for an example, and for more examples on how to use the plugin.

Planned improvements:

  • styling from configuration page
  • configuration of licenses to search for
  • more caching of rest call results
  • integrate the gallery into the plugin
  • provide a default theme
  • search by geolocation

Great news in the software world

During the last week there has been a couple of great releases in the software I use every day.


First out was Python 3.1. It was released June 27th and features

  • An ordered dictionary type
  • Various optimizations to the int type
  • New unittest features including test skipping and new assert methods.
  • A much faster io module
  • Tile support for Tkinter
  • A pure Python reference implementation of the import statement
  • New syntax for nested with statements


Next out was Mozilla Firefox 3.5, which was released earlier today (June 30th), most noteworty items from that release is the @font-face css-attribute, that allows web-designers to bundle custom fonts with their website designs, and use custom fonts in their design.  I have used that feature to change the header of my blog, you would se a grudge font if you use the new Firefox or Safari. They have also released a new javascript-engine, which they claim to be a lot faster than the old one. Also, support for the <video>-tag has been added.


Then last, but not least, the long awaited PHP 5.3.0 has been released, which provides namespaces and closures for PHP.

Merging two lists

Lets say you have two lists, one of them containing the values [1,2,3] and the other one containing the values [4,5,6], and you want to combine these two lists into one list, like this one: [1,2,3,4,5,6].

Let’s see how this can be done in different (high level) programming (or scripting or templating) languages.

Java

Java has multiple list implementations, lets start with the most basic one, the builtin array.

int[] A = {1,2,3};
int[] B = {4,5,6};
int[] C = new int[A.length + B.length];
int counter=0;
for(int e : A){
  C[counter]=e;
  counter++;
}
for(int e : B){
  C[counter]=e;
  counter++;
}

or with an ArrayList:

/*Dropped importing the correct classes, 
and constructing the ArrayLists A and B, since thats not the focus here...*/
List<Integer> C = new ArrayList();
C.addAll(A);
C.addAll(B);

PHP

So, how is the same done in PHP?

$A=array(1,2,3);
$B=array(4,5,6);
$C=array_merge($A,$B);

Python

And at last, how does the Pythonistas do this?

?View Code PYTHON
A=[1,2,3]
B=[4,5,6]
C=A + B

Note: the rubyists use the same approach.

Merkelapper

De observante der ute (og som ikke bare leser bloggen min fra rss-leseren sin) kan ha oppdaget at merkelappene på bloggpostene har fått et nytt utseende.

Det begynte egentlig med at jeg så på en post jeg hadde skrevet og tenkte “Hm, de taggene der ser ikke ut som om de egentlig hører hjemme der”. Videre tenkte jeg, hva skal jeg gjøre for å få dem mer inn i det visuelle uttrykket på bloggen. Det hadde vært fint med noen bilder, men da må jeg vedlikeholde en haug med bilder for alle taggene. Det har jeg forsøkt før, da bare for kategoriene, og det er nesten ti ganger så mange tagger som kategoriene.

Hva om jeg kunne lage en bakgrunn som fikk merkelappene til å se mer ut som merkelapper? Vel.. min assosiasjon til merkelapper i denne sammenhengen er slike brune lapper som brukes på postsekker. Jeg kunne alltids lage en bakgrunn som så slik ut, men jeg syntes det ville være rart om de bare gikk rett horisontalt.

Her kommer vi til en av de tingene som jeg har savnet i CSS. En mulighet til å rotere objekter.

Velvel. vi kan jo alltids generere bilder på serveren, og bruke det… Og det var akkurat det jeg endte opp med også. Ikke bare får jeg da generert merkelappene slik jeg vil ha dem, men jeg kan velge den fonten jeg vil ha også, selv om webfonts ikke er støttet i nettleserene enda.

Resultatet er merkelappene nedenfor, og php-koden som genererer dem finner du her
Og her er det jeg brukte for å putte det inn i wordpress-temaet

WordPress 2.7 is out

WordPress 2.7 final was announced today.
I just upgraded to wordpress 2.7. It took me about 30 seconds :D , thanks to svn switch.

tar -czf backup.tar.gz blog.elzapp.com
mysqldump -u root -p -- elblogg &gt; backup.sql
svn sw http://svn.automattic.com/wordpress/tags/2.7

There! that’s it. :D

Now, what’s my first impressions?

  • It looks very nice
  • It is VERY much slower than WordPress 2.6.5, that’s atleast my first impression.

I haven’t played much around with it yet. I basicly installed, and went right away writing this post.

Should have guessed it

I have sort of a love/hate relationship with Python, the programming language. Coming from PHP and Java which both have excellent documentation, while lots can be said about the solutions. With Python 2.6 the documentation really has improved, but its still not really there, while the solutions are so elegant that the only reason you don’t guess how to do stuff is that it feels too simple.

Today I had one of these realizations, while reading Wayne’s snippet of the day.

Python has a really nice list-generation scheme, so you can generate lists of the content you want from another list of object with only one line of code.

Example:

?View Code PYTHON
&gt;&gt;&gt; from math import floor
&gt;&gt;&gt; a = [1.5, 1.9, 2.5, 3.1, 5.7]
&gt;&gt;&gt; b = [floor(i) for i in a]
&gt;&gt;&gt; print b
[1.0, 1.0, 2.0, 3.0, 5.0]

Here I generated a list of whole numbers from a list of non-whole numbers.

Now We’ll take this further.
Lets say we want to filter the list, so we’ll only get the numbers that satisfy 1<=x<2.

We could do this using filter() and lambda functions. Which is totally OK. It'll make Python newbies totally confused (which it did with me until recently, when I realized what lambda functions really are (I'll get back to this)), but it'll work nicely.

But wouldn't it be nice if we could use the same list generation scheme for this as well?
Guess what. You can!

?View Code PYTHON
&gt;&gt;&gt; a = [1.5, 1.9, 2.5, 3.1, 5.7]
&gt;&gt;&gt; b = [i for i in a if 1<=i and i<2]
&gt;&gt;&gt; print b
[1.5, 1.9]

Doing the same using filter and a lambda function will look like this

?View Code PYTHON
&gt;&gt;&gt; a = [1.5, 1.9, 2.5, 3.1, 5.7]
&gt;&gt;&gt; b = filter(lambda x: 1<=x and x<2, a)
&gt;&gt;&gt; print b
[1.5, 1.9]

and without using a lambda function:

?View Code PYTHON
&gt;&gt;&gt; def myfilter(x):
&gt;&gt;&gt;     return x: 1<=x and x<2
&gt;&gt;&gt; a = [1.5, 1.9, 2.5, 3.1, 5.7]
&gt;&gt;&gt; b = filter(myfilter, a)
&gt;&gt;&gt; print b
[1.5, 1.9]

All of these will work equally fine, and none of them is very hard to understand, as long as you keep in mind that lambda functions just are like anonymous functions/classes.

But there is something very facinating with the elegance and simplicity in the syntax of the list generator snippet.

Upgrading WordPress to 2.5

According to Stuart Herbert, if you use the advanced TinyMCE editor instead of the builtin wysiwyg editor, disable it before upgrading. Its not compatible with 2.5 (yet).

On the other hand, always disable all plugins before upgrading, and enable them one by one afterwards.

And, Bjørge, I will get back to what I did to make WP-upgrading easy soon.

Bloggurat Twingly BlogRank Blogglisten