Monday, February 6, 2017

[Linux] Get list of local IPv4 addresses in C++

#include <stdio.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <net/if.h>

int main()
{
    struct ifaddrs* ifap;
    getifaddrs(&ifap);

    for (ifaddrs* ifa = ifap; ifa; ifa = ifa->ifa_next)
    {
        if ((AF_INET == ifa->ifa_addr->sa_family) && ((ifa->ifa_flags & IFF_UP) > 0) && (0 == (ifa->ifa_flags & IFF_LOOPBACK)))
        {
            struct sockaddr_in* sa = (struct sockaddr_in *) ifa->ifa_addr;
            char* addr = inet_ntoa(sa->sin_addr);
            printf("%s\n", addr);
        }
    }

    freeifaddrs(ifap);

    return 0;
}

Tuesday, January 10, 2017

[HowTo] Call any code on UI thread outside of Activity

using Android.OS;

public class MyThread
{
    public void Run()
    {
        RunOnUiThread(() => DoSomething());
    }

    private void RunOnUiThread(Action action)
    {
        using (var handler = new Handler(Looper.MainLooper))
        {
            handler.Post(action);
        }
    }
}

Tuesday, January 3, 2017

[HowTo] Locate drives in hot-swap bays in Super Micro servers using LED


Friday, December 23, 2016

[HowTo] Boot Acer Aspire Switch 10 from a USB stick


Thursday, December 22, 2016

[HowTo] Make a Windows application full screen


MONITORINFO monitorInfo = { sizeof(monitorInfo) };
if (GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &monitorInfo))
{
    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME));
    SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));

    SetWindowPos(hwnd, NULL, monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top,
        monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top,
        SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}