browse by category or date

I just found out this trick to make your WordPress image upload automatically shown in Lightbox. In order for this trick to works, you need to install NextGen Gallery plugin into your WordPress installation. This doesn’t mean we upload the image into NextGen Gallery, then show the gallery in the post.

Normally, when after we uploaded image to WordPress we are going to see this dialog:


After added the image into Post, we are going to see this added into editor:

<a href="http://sodeve.net/wp-content/uploads/2012/10/ec2.8.png">
  <img src="http://sodeve.net/wp-content/uploads/2012/10/ec2.8-300x178.png"
  alt="" title="ec2.8" width="300" height="178"
  class="aligncenter size-medium wp-image-2980" />
</a>

In above code, whenever a visitor clicked the thumbnail, the page will load the image in full size. Which is bad, because when the visitor wants to continue reading, he/she needs to go back to the page.

To make the image shown in lightbox, we just need to add class shutterset_set_X into the image. Please change the X into a number. This way you can group the images in lightbox accordingly.

<a href="http://sodeve.net/wp-content/uploads/2012/10/ec2.8.png"
class="shutterset_set_1">
  <img src="http://sodeve.net/wp-content/uploads/2012/10/ec2.8-300x178.png"
  alt="" title="ec2.8" width="300" height="178"
  class="aligncenter size-medium wp-image-2980" />
</a>

That’s all folks! If the trick is useful, please share it away. If it doesn’t work on your blog, drop a comment and we’ll see what we can do.

Cheers!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

F# is a functional programming language that recently officially added to Visual Studio.NET supported languages. To me it reminds me alot to Python because of the indentation rules. If you want to play around with this language, you could either use:

  1. Visual Studio 2010
  2. Visual F# 2011 CTP
  3. Visual Studio 2012 Developer Preview
  4. Your browser

What made me attracted so much to F#? It was caused by this informative, interesting and humorous session by Luca Bolognese. And yes, since he’s an Italian, his introduction to programming in F# is an offer that I can’t refuse! 😀

In his talk, Luca highlighted three most important keywords in F#. They are:

  1. let. This keyword is similar, but different to var in C# or Dim in VB. But let is actually more on binding one object/value to a symbol. This symbol will be an immutable object, which means the its value/object can’t be change during its life-cycle.
  2. |>. This operator is similar to pipe in MS-DOS.
  3. fun. This keyword is used in creating lambda function.

Luca also highlighted that F# gives you the facility to immediately concentrate on the core solution of the problem. Because in F#, Luca said, we can program the solution of a problem just like the way we would solve it in our brain.

Anyway, let’s get dirty with simple example in F#:

//bind x to an integer
let x = 10;

//create a list of integers
let data = [1;2;3;4]

//define a square function
let sqr x = x * x 

//Luca notes that this method is something that we will do 
//in C#
let sumOfSquaresI nums =
    //"let mutable" will create a variable instead of binding to a symbol
    let mutable acc = 0
    for x in nums do
        //assign value to acc
        acc <- acc + sqr x
    //return the value
    acc

//This is the same function, but in a recursive function
let rec sumOfSquaresF nums =
    //match is a branching mechanism plus binding
    match nums with
    | [] -> 0
    //h::t will match to a list 
    //and bind symbol h to the first element of the list
    //and bind symbol t as the rest of the elements in the list
    | h::t -> sqr h + sumOfSquaresF t

//This is the F# way of doing Sum of Squares
let sumOfSquares nums =
    nums
    //Operator |> is similar to a DOS pipeline
    //Seq.map will apply the function sqr to each elements in the list
    |> Seq.map sqr
    //By now the list we have is a list of squares, e.g. [1;4;9;16]
    //Seq.sum will sum every elements in the list and return an integer
    |> Seq.sum

From above code, I hope we can quickly spot the difference between programming in imperative way (sumOfSquaresI) vs. the F#-way (sumOfSquares). Clearly, the F#-way gives us not many room to make mistake, and if you think of it, it is indeed how we would solve it in our brain (first, square every element in the list, then sum it up).

Another plus point is parallelization. Parallelization is very much working out of the box in F#. We can easily parallelize the function sumOfSquares by calling the parallel-version of the method.

let sumOfSquares nums =
    nums
    |> Seq.pmap sqr
    |> Seq.psum

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

It feels great when I realized that I’ve just found out a new way of doing things. But it feels kinda sucks when that “new way” is apparently has been around for quite sometime. It did made me feel bad about myself a little. Because that means either I have not been looking hard enough, or I didn’t even bother to find out because I can use my old method to achieve the same result (a.k.a. Comfort Zone Leaving Avoidance Syndrome). 😀

Since this problem is related to MS SQL Database, we need to imagine that we have this condition:

  1. There are two tables, Categories (key: CategoryID) and Posts (has a CategoryID field)
  2. Posts to Categories is in 1-to-1 relationship

Now we are required to keep track of how many Posts under a particular Category. For that purpose, an integer field called PostCount is added to Categories table. In order to maintain the correct PostCount value, triggers would need to be added in Posts table. These triggers will be invoked whenever a Post is created, updated and deleted. But before that, we need to run an update query to initialize the PostCount value. And this update query is where I learned my “no-longer-new way”.

If you asked me to do this last week, I would definitely insisted that this is unworkable in SQL. I would then quickly write a small program to:

  1. Retrieve all the Categories
  2. Iterate each Category, and count how many Posts with this Category
  3. Update Category

Fortunately, the request insisted that it must be done in SQL. Thus, it forced me to trial and error, as well Googling for it. As I found out today after many trials, above steps could be done in SQL. Here’s how:

Update CCC
Set CCC.PostCount = PPP.Counted
From Categories CCC
Inner Join (
   Select CategoryID, Count(*) as Counted
   From Posts
   Group By CategoryID
) PPP
on CCC.CategoryID=PPP.CategoryID;

The joy of finding out this method was significantly reduced when I found out that this guy blogged about it almost 5 years ago! 😀

Cheers!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: