Sometimes you need to calculate the price of a product excluding VAT, and the only details you have is the amount including vat and the vat percent. This might be a bit tricky in some applications when there are mixed VAT percentages. For example, you payed 1000 space credits and in that sum there is… Read More »
Simple way to sort an array with usort on a specific value using a comparator.
A simple function to convert dp into pixels. Use when you have to pass pixels to a method and want to keep everything to scale. From Android Developer Center : pxPixels – Corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each… Read More »
Here’s a super simple function that generates humanly readable passwords by weaving random consonants and wovels. The generated passwords are by no means secure. I did this for an application used to launch game servers and wanted to make the passwords be easy to communicate over Skype.
Put this in a static class. This will apply to Lists of any type. Simply call it like this
Lets say you have a list of person objects (List persons) You may use Sort to update the existing list. or OrderBy to produce a new, ordered list.
Here’s a simple way to paginate when getting large amounts of posts from the database.
Converting seconds into days, hours, minutes and seconds int days = secondsTotal / 60 / 60 / 24; int hours = (secondsTotal / 60 / 60) % 24; int minutes = (secondsTotal / 60) % 60; int seconds = secondsTotal % 60;
Sometimes you need to check if a number is even or odd. A simple way to do this is using the modulus operator (the %-sign). It will calculate and return the remainder when dividing a value with another value. So how do you use that to find out if a number is even or odd?… Read More »