{blog}


  • (Android) Set focus to dialog programmatically

    To get the keyboard to pop up after creating a dialog:

    dialog.getWindow().
      setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
      
    dialog.show();
    Java

  • (Java) Convert milliseconds to minutes and seconds (mm:ss)

    For a nice string representation, using the TimeUnit lib:

    String.format("%02d:%02d",
    TimeUnit.MILLISECONDS.toMinutes(milliSeconds),
    TimeUnit.MILLISECONDS.toSeconds(milliSeconds) -
    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliSeconds)));
    Java

    or simply do the math:

    int minutes = (int) (milliSeconds/ 1000) / 60;
    int seconds = (int) (milliSeconds/ 1000) % 60;
    Java

    and back to miliseconds again:

    long milliSeconds= ((minutes * 60) + seconds) * 1000;
    Java

  • (Android) Prevent config change on orientation change

    Add to activity in manifest:

    android:configChanges="keyboardHidden|orientation|screenSize"
    XML

  • CSS3 box shadow

    A nice feauture in CSS3 is the box-shadow. Instead of working with tedious PNG-images you can add shadows to any element with the CSS property box-shadow.

    The syntax works like this:

    box-shadow: <offset-x> <offset-y> <blur> <spread> <color> <inset>

    • The offset settings will set the angle of the shadow. Where it will be cast in relation to the element.
    • Blur with set how much the shadows blurs out from its defined position.
    • Spread will set the size of the shadow. By default the same size as the element. This number can be negative to set a smaller shadow.
    • Color can be any  format. i.e. black, yellow, #FFF, rgb(255, 240, 240) or rgba(0, 0, 0, 0.7)
    • Using the inset option will cast the shadow inside the element instead of outside.

    Here are some examples:

    (more…)


  • Super simple navigation menu

    Here is a super simple navigation bar. Customize it for your site, with colors and fonts.
    This is just a super simple base recipe:

    First the html:

    [code language=”html”]
    <ul class="menubar">
    <li><a href="#">hem</a></li>
    <li><a href="#">info</a></li>
    <li><a href="#">tjänster</a></li>
    <li><a href="#">kontakt</a></li>
    </ul>
    [/code]
    (more…)


  • (C#) Generate random readable passwords

    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. (more…)


  • (C#) Swap two items in a generic list

    Put this in a static class. This will apply to Lists of any type.
    [c language=”language="#”]
    public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB)
    {
    if (indexB > -1 && indexB < list.Count)
    {
    T tmp = list[indexA];
    list[indexA] = list[indexB];
    list[indexB] = tmp;
    }
    return list;
    }
    [/c]

    Simply call it like this
    [c language=”language="#”]
    myList.Swap(indexA, indexB);
    [/c]


  • (C#) Sort lists

    Lets say you have a list of person objects (List persons)

    You may use Sort to update the existing list.
    [c language=”#”]
    personsList.Sort((x, y) => string.Compare(x.Name, y.Name));
    [/c]
    or OrderBy to produce a new, ordered list.
    [c language=”#”]
    var newPersonsList = persons.OrderBy(x => x.Name);
    [/c]


  • (PHP) Simple pagination

    Here’s a simple way to paginate when getting large amounts of posts from the database.

    (more…)


  • Generate dummy data

    Here’s a great tool for generating dummy data for your database etc.
    www.generatedata.com