• Improving test output in Gradle

    If you’ve ever ran tests in Gradle, you might have noticed that the output on failing tests are quite sub-par. This becomes an issue on Travis specifically, as you cannot debug the results and to get more infomation on the test, you must enable the --stacktrace flag. By default, Gradle does not output which tests have been run, something which could be useful.

    Another thing I find useful is to see any console output. You could enable the --info or --debug flag, but I feel that Gradle clutters this too much. For my projects, I prefer using this test configuration to get the most information possible, without cluttering the output too badly.

    This will output anything written to the console (including lint errors), print the full stack traces and list all tests ran.

    tasks.withType(Test) {
        testLogging {
            exceptionFormat "full"
            showCauses true
            showExceptions true
            showStackTraces true
            showStandardStreams true
            events = ["passed", "skipped", "failed", "standardOut", "standardError"]
        }
    }
    

  • Ascii Art Generator

    Sun, beer, volleyball, travel, bathing, swimming, longboarding, and of course… programming!

    It is the time of year when I have the time to dedicate time to some personal projects. Today has been a long day of coding and the result was a JavaScript Ascii Art Generator. I have been doing some image manipulation using HTML5 recently and this was simply a natural next step. The image above shows the result from a render i did.

    The applications is stand alone and can handle most images, although images with a lot of contrast seems to work the best. The current version works well, but I might want to tweak it at a later point to get be able to handle darker images better.

    If you want to give it a try, you can find it at the GitHub Repo.

    I have also got myself a longboard. It is much easier to start out with than I would have thought and it is so much fun! The thought is to use it as a means of transport, but at my current skill level I am most like better off simply walking.

  • PHP Server redirect

    After a couple months of moving, putting together IKEA furniture and reconfiguring servers and devices there is still one thing missing; a static IP. I am currently running OpenProject as my choice of project management tool. The challenge of using this is that it runs on Ruby, so it has to be hosted on one of my servers and these are placed in my apartment at the moment.

    Normally, when having a static IP you would simply add a CNAME record for the IP and it would have been working as intended. At the moment this is unfortunately not the case. So how do we get around this?

    In my case, only HTTP needs to be supported at the moment so the solution was making a simple PHP script handling the redirection. This stores the server IP on request and redirects everything else. It also handles subdirectories and GET requests correctly.

    To use the script, create a folder with the desired name of your server(server1.your-domain.com) would be achieved by creating a folder named server1 in the root directory of your web host. Then all you have to do is extract the source in that directory and create a cron job on your server for updating the server IP. Remember to update your auth token in index.php.

    Cron Job setup

    Append the following content to your crontab:

    */10 * * * * wget -q -O /dev/null "https://<folder-name>.your-domain.com/?action=set&auth=<your-auth-code>"

    Save and exit.

    Example usage

    Manually update your server IP to your current public IP
    https://server1.your-domain.com/?action=set&auth=eVZKwTTFYASm6orAgzjm

    Retrieve the server IP in a browser
    https://server1.your-domain.com/?action=get

    Get your server IP in a terminal
    $ echo Server ip is: $(curl -sL https://server1.your-domain.com/?action=get)

    Get the code

    You can download the source here: server-redirect.zip .

  • Console debugging in PHP

    Recently, I have been playing around in PHP again and found that I missed the simplicity of printing whatever object I wanted to the JavaScript console. Guess what? Now we all can!

    After some fooling around, I ended up with the following class for handling it. Although it requires your code not to crash, I found it very useful when handling exceptions and inspecting objects when I set up a new API recently.

    The attached archive includes both the source and example usage of the script. So sum it up, what you need to get started is this:

    <?php
        require_once("ConsoleDebug.php");
        use \Net\Nexcius\ConsoleDebug as Debug;
    
        Debug::LogD("This is a debug message");
    ?>

    As always, feel free to use it however you like.

    » Continue reading

  • Loading meshes using Assimp in OpenGL

    I have been catching up on OpenGL 4.4 lately and realized that there are few working examples on the newer versions of OpenGL. The following code uses Assimp, GLFW and GLEW to load and render all supported Assimp formats and requires OpenGL 3.0 or above.

    You will be required to set up an OpenGL context, I will presume that you have the knowledge to do that (if not, I can recommend this tutorial from opengl-tutorial.org).

    To use the Mesh class, this is all that is required:

    Mesh *mesh = new Mesh("filename.dae");
    while (!glfwWindowShouldClose(window)) {
    	mesh->render();
    }
    delete m;

    The combined source and example shaders can be downloaded at the bottom of this page.

    » Continue reading

  • Object-oriented JavaScript

    Any project using JavaScript tend to quickly grow out of proportions and often results in very messy code. There are some good tools out there for making it easier to write and maintain JS code, one of which I like the best: CoffeScript. Using these kind of tools helps a lot, but today I’ll present one way of making JavaScript more readable.

    By applying object-oriented programming to JavaScript, it’s readability, modularity and reusability are greatly improved. Object-oriented languages has been around since Simula appeared in 1967, and is used by some of the most common languages like C++, C# and Java.

    As JavaScript does not have native support for classes, but is able to use anything as as variable there are a couple different methods of making classes in JS. I’ll present the one that I think is most intuitive. Let’s get to it.

    Namespace definition

    Using namespaces in JavaScript allows us to further separate the classes and avoids variable duplication. To do this, we need to define the namespaces as objects. To define the namespace “net.netxcius”, the following code is required:

    var net = {
        nexcius: {}
    };

    Class example

    The following code defines our variable as a function. This is what will contain everything that we would normally place inside a class. The outermost function is called a self invoking function, this means that is calls itself upon creation. This is not required, but it has one great advantage: it can contain area specific global variables (Sarfraz Ahmed has a good blog post on this: Javascript Self Invoking Functions).

    » Continue reading

subscribe via RSS