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 »
Principle 1. Always have a clear image of what you want to do BEFORE you start writing your code. Then break it down in logical instructions – making an algorithm. An algorithm is a step by step instruction on how to solve a specific problem. You might think of it as a recipe. If you… Read More »