text:
module.controller('widgetsCtrl', function ($scope, $modal, widgetsSrv, templateSrv) {
    $scope.getWidgetList = function (row) {
        widgetsSrv.getWidgetList(row, $scope.widgetsPerPage).then(function (response) {
            $scope.widgetList = widgetsSrv.widgetList;
            $scope.widgetCount = widgetsSrv.widgetCount;
        });
    };

    $scope.saveWidget = function (widgetObject) {
        var formToken = document.getElementById('FORM_SECURITY_TOKEN').value;
        widgetsSrv.createNewWidget(widgetObject, formToken).then(function (response) {
            $scope.getWidgetList(row, numRows);
        });

    };
    var openWidgetModal = function (widget) {
        var template = templateSrv.widgetModal;
        var modalInstance = $modal.open({
            templateUrl: template,
            controller: 'widgetModalInstanceController',
            size: 'lg',
            resolve: {
                widget: function () {
                    return widget;
                }
            }
        });

        modalInstance.result.then(function () {
            $scope.getWidgetList(row, numRows);
        },
        function () {
        });
    };

    $scope.editWidget = function (widget) {
        openWidgetModal(widget);
    };

    $scope.addNewWidget = function () {
        openWidgetModal();
    };

    $scope.deleteWidget = function (widget) {
        var confirmed = confirm('Are you sure you want to delete ' + widget.name + '?');
        if (confirmed) {
            widgetsSrv.deleteWidget(widget).then(function () {
                $scope.getWidgetList(row);
            });
        }
    };

    $scope.$watch('currentPage + numPerPage', function () {
        row = (($scope.currentPage - 1) * $scope.widgetsPerPage);
        numRows = $scope.widgetsPerPage;

        $scope.getWidgetList(row, numRows);
    });

    // Stuff to run on controller load
    $scope.widgetsPerPage = 10;
    $scope.currentPage = 1;

    var row = (($scope.currentPage - 1) * $scope.widgetsPerPage);
    var numRows = $scope.widgetsPerPage;
});

module.controller('widgetModalInstanceController', function ($scope, $modalInstance, widget, widgetsSrv) {
    $scope.widget = widget;

    $scope.confirm = function () {
        var formToken = document.getElementById('FORM_SECURITY_TOKEN').value;
        widgetsSrv.saveWidget($scope.widget, formToken).then(function (response) {
            if (!response.data.result || response.data.result !== 'error') {
                $modalInstance.close();
            }
        });

    };

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
});

// Pages controller

module.controller('pageTemplatesCtrl', function ($scope, $modal, pageTemplatesSrv, templateSrv) {

    function getPageTemplatesList(row, numRows) {
        pageTemplatesSrv.getPageTemplatesList(row, numRows).then(function (response) {
            $scope.pageTemplatesList = pageTemplatesSrv.pageTemplatesList;
            $scope.totalItems = pageTemplatesSrv.pageTemplatesCount.rowCount;
        });
    }

    var openPageTemplateModal = function (pageTemplate) {
        var template = templateSrv.pageTemplateModal;
        var modalInstance = $modal.open({
            templateUrl: template,
            controller: 'pageTemplateModalInstanceController',
            size: 'lg',
            resolve: {
                pageTemplate: function () {
                    return pageTemplate;
                }
            }
        });

        modalInstance.result.then(function () {
            getPageTemplatesList(row, numRows);
        },
        function () {
        });
    };

    $scope.addNewPageTemplate = function () {
        openPageTemplateModal();
    };

    $scope.editPageTemplate = function (pageTemplate) {
        openPageTemplateModal(pageTemplate);
    };

    $scope.deletePageTemplate = function (pageTemplate) {
        var confirmed = confirm('Are you sure you want to delete ' + pageTemplate.name + '?');
        if (confirmed) {
            pageTemplatesSrv.deletePageTemplate(pageTemplate)
                    .then(function () {
                        getPageTemplatesList(row, numRows);
                    });
        }
    };

    $scope.$watch('currentPage + numPerPage', function () {
        row = (($scope.currentPage - 1) * $scope.itemsPerPage);
        numRows = $scope.itemsPerPage;

        getPageTemplatesList(row, numRows);
    });

    $scope.itemsPerPage = 10;
    $scope.currentPage = 1;

    var row = (($scope.currentPage - 1) * $scope.itemsPerPage);
    var numRows = $scope.itemsPerPage;
});

module.controller('pageTemplateModalInstanceController', function ($scope, $modalInstance, pageTemplate, pageTemplatesSrv) {
    $scope.pageTemplate = pageTemplate;

    var getUnusedWidgets = function (pageTemplate) {
        pageTemplatesSrv.getUnusedWidgets(pageTemplate)
                .then(function (response) {
                    $scope.unusedWidgetList = pageTemplatesSrv.unusedWidgetList;
                });
    };

    var getWidgetsOnPageTemplate = function (pageTemplate) {
        if (pageTemplate) {
            pageTemplatesSrv.getWidgetsOnPageTemplate(pageTemplate)
                    .then(function () {
                        $scope.widgetsOnPage = pageTemplatesSrv.widgetsOnPage;
                    });
        }
    };

    $scope.getWidgetByName = function (widgetName) {
        for (var widget in $scope.unusedWidgetList) {
            if ($scope.unusedWidgetList.hasOwnProperty(widget)) {
                if ($scope.unusedWidgetList[widget].name === widgetName) {
                    $scope.widgetObjectToAdd = $scope.unusedWidgetList[widget];
                }
            }
        }
    };

    $scope.addWidgetToPage = function (pageTemplate, object, sectionName, ymlKey) {
        var formToken = document.getElementById('FORM_SECURITY_TOKEN').value;
        pageTemplatesSrv.addWidgetToPage(pageTemplate, object, sectionName, ymlKey, formToken)
                .then(function (response) {
                    $scope.widgetToAdd = undefined;
                    document.getElementById('widgetToAdd').value = '';
                    getWidgetsOnPageTemplate($scope.pageTemplate);
                    getUnusedWidgets();
                });
    };

    $scope.removeWidgetFromPage = function (widget) {
        var confirmed = confirm('Do you want to remove ' + widget.name + '?');
        if (confirmed) {
            pageTemplatesSrv.removeWidgetFromPage($scope.pageTemplate, widget)
                    .then(function (response) {
                        getWidgetsOnPageTemplate($scope.pageTemplate);
                        getUnusedWidgets();
                    });
        }
    };

    $scope.saveAndContinue = function (pageTemplate) {
        var formToken = document.getElementById('FORM_SECURITY_TOKEN').value;
        pageTemplatesSrv.savePageTemplate(pageTemplate, formToken).then(function (response) {
            $scope.pageTemplate = response.data.WidgetPage[0];
        });
    };

    $scope.confirm = function () {
        var formToken = document.getElementById('FORM_SECURITY_TOKEN').value;
        pageTemplatesSrv.savePageTemplate($scope.pageTemplate, formToken)
                .then(function (response) {
                    if (!response.data.result || response.data.result !== 'error') {
                        $modalInstance.close();
                    }
                });
    };

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };

    var row = (($scope.currentPage - 1) * $scope.itemsPerPage);
    var numRows = $scope.itemsPerPage;

    getWidgetsOnPageTemplate(pageTemplate);
    getUnusedWidgets(pageTemplate);
});


text:
import zlib
import random
import base64
import xmlrpclib

class OpenSubtitle:

	# Url de l'api
	url = 'http://api.opensubtitles.org/xml-rpc'
	infoVideo = {'hash':'', 'imdbid':'', 'name':'', 'year':'', 'season':'', 'episode':'', 'size':'', 'hashSub':'', 'nameData':''}
	subHash = []
	#Langue des sous-titres souhaité, avec 0 pour non trouvé et 1 pour trouvé
	language = {'English':0, 'French':0}

	def __init__(self,hashVideo,size,name):
		self.infoVideo['hash'] = hashVideo
		self.infoVideo['size'] = size
		self.infoVideo['nameData'] = name

	def serverInfo(self):
		server = xmlrpclib.Server(self.url)
		return server.ServerInfo()

		#Connexion à l'API
	def Login(self):
		server = xmlrpclib.Server(self.url)
		resp = server.LogIn("","","fr","MyAPP V2")
		self.token = str(resp["token"])
		return (resp)

		#Vérification de l'existence du HASHSUB dans la bdd
	def CheckSubHash(self):
		server = xmlrpclib.Server(self.url)
		resp = server.CheckSubHash(self.token,[self.infoVideo['hashSub']])
		return (resp)

		#Récupération d'info à partir du hash
	def CheckMovieHash(self):
		server = xmlrpclib.Server(self.url)
		resp = server.CheckMovieHash(self.token,[self.infoVideo['hash']])

		if len(resp['data'][self.infoVideo['hash']]) != 0:
			self.infoVideo['imdbid'] = str(resp['data'][self.infoVideo['hash']]['MovieImdbID'])
			self.infoVideo['name'] = str(resp['data'][self.infoVideo['hash']]['MovieName'])
			self.infoVideo['year'] = str(resp['data'][self.infoVideo['hash']]['MovieYear'])
			self.infoVideo['season'] = str(resp['data'][self.infoVideo['hash']]['SeriesSeason'])
			self.infoVideo['episode'] = str(resp['data'][self.infoVideo['hash']]['SeriesEpisode'])
		else:
			resp = 'Error'

		return (resp)

		#Récupération d'info à partir du hash v2
	def CheckMovieHash2(self):
		server = xmlrpclib.Server(self.url)
		resp = server.CheckMovieHash2(self.token,[self.infoVideo['hash']])

		if self.infoVideo['hash'] in resp['data']:
			self.infoVideo['imdbid'] = resp['data'][self.infoVideo['hash']][0]['MovieImdbID']
			self.infoVideo['name'] = resp['data'][self.infoVideo['hash']][0]['MovieName']
			self.infoVideo['year'] = resp['data'][self.infoVideo['hash']][0]['MovieYear']
			self.infoVideo['season'] = resp['data'][self.infoVideo['hash']][0]['SeriesSeason']
			self.infoVideo['episode'] = resp['data'][self.infoVideo['hash']][0]['SeriesEpisode']
		else:
			resp = 'Error'

		return (resp)

		#Recherche des sous-titres
	def SearchSubtitles(self,order):
		server = xmlrpclib.Server(self.url)
		content = []
		if(order == 1):
			content.append( { 'moviehash':self.infoVideo['hash'],
								'moviebytesize':self.infoVideo['size']} )
		elif(order ==2):
			content.append( { 'imdbid':self.infoVideo['imdbid']} )

		elif(order == 3):
			content.append( { 'name':self.infoVideo['name']} )
		elif(order==4):
			content.append( { 'query':self.infoVideo['name'],
								'season':self.infoVideo['season'],
									'episode':self.infoVideo['episode']} )
		else:
			content.append( { 'query':self.infoVideo['nameData']})

		resp = server.SearchSubtitles(self.token, content)

		try:
			for i in range(0,len(resp['data'])):
				self.subHash.append({'id':resp['data'][i]['IDSubtitleFile'],'hashSub':resp['data'][i]['SubHash'],'lang':resp['data'][i]['LanguageName']})
		except:
			resp = 'Error'
		return (resp)

		#Vérification si le sous-titres a été téléchargé
	def chechDLSubtitle(self,lang,type):
		if type == 0:
			if self.language[lang] == 0:
				return False
			else:
				return True
		elif type == 1:
			resp = True

			for lang in self.language.values():
				if lang == 0:
					resp = False
					break
			return (resp)
		else:
			return "Error"

		#Téléchargements des sous-titres
	def DownloadSubtitles(self,):
		server = xmlrpclib.Server(self.url)
		resp= ""

		for j in self.language:
			if self.chechDLSubtitle(j,0) == False:

				for i in range(0,len(self.subHash)):
					if self.subHash[i]['lang'] == j:

						self.language[j] = 1 #Sous-titre trouvé on met donc la valeur à 1

						resp = server.DownloadSubtitles(self.token,[self.subHash[i]['id']])
						resp = base64.standard_b64decode(resp['data'][0]['data'])
						resp = zlib.decompress(resp, 47 )
						rnd = random.randrange(1000,999999)

						name = self.infoVideo['name'].replace("'","_")
						name = self.infoVideo['name'].replace('"',"_")
						sub_file = (j[0:2]).upper()  + name + '_' + str(rnd) + '.srt'

						f = open(sub_file,'wb')
						f.write(resp)
						f.close()
						break
		return ()

		#Insertion du hash de la vidéo sur le site
	def InsertMovieHash(self):
		server = xmlrpclib.Server(self.url)
		content = []
		content.append( { 'moviehash':self.infoVideo['hash'],
								'moviebytesize':self.infoVideo['size'],
									'imdbid':self.infoVideo['imdbid']} )

		self.resp = server.InsertMovieHash(self.token,content)
		return (self.resp)

		#Déconnexion
	def Logout(self):
		server = xmlrpclib.Server(self.url)
		server.LogOut(self.token)
		print "\n LOGOUT"

redpajama_set_name: RedPajamaGithub


text:
const path = require("path");
const root = path.join(__dirname, "/../../");

const fav = require("serve-favicon");
const favicon = fav(path.join(__dirname, "../../public/images/favicon.ico"));

const connectionStrings = {
    production: process.env.CONNECTION_STRING,
    development: "mongodb://localhost/FindYourTransportDb"
};

module.exports = {
    environment: process.env.NODE_ENV || "development",
    db: connectionStrings[process.env.NODE_ENV || "development"],
    port: process.env.PORT || 8080,
    root,
    favicon
};


text:
<!--

    Licensed to Apereo under one or more contributor license
    agreements. See the NOTICE file distributed with this work
    for additional information regarding copyright ownership.
    Apereo licenses this file to you under the Apache License,
    Version 2.0 (the "License"); you may not use this file
    except in compliance with the License.  You may obtain a
    copy of the License at the following location:

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
<!DOCTYPE html>
<html lang="en-US" class="respondr">
<head>
  <base href="/">
  <link ng-if="portal.theme.name" ng-href="css/themes/{{portal.theme.name}}.css" rel="stylesheet" type="text/css"/>
  <!-- build:include ../components/head-static.html -->
  This will be replaced by the content in head-static.html
  <!-- /build -->
</head>

<body>

  <!-- build:include ../components/static.html -->
  This will be replaced by the content of static.html
  <!-- /build -->

  <!--The MyUW Body-->
  <uw-body></uw-body>

  <!--javascript-->
  <script type="text/javascript" src="js/config.js"></script>
  <script type="text/javascript" src="js/ga.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="main"></script>

</body>
</html>


text:
<!DOCTYPE html>

<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="1;url=http://sensotrend.jelastic.planeetta.net/Taltioni/MovesAuthentication">

<title>Moves2Taltioni</title>

Start authenticating!


text:
/*
 * vim:ts=4:sw=4:expandtab
 *
 * i3 - an improved dynamic tiling window manager
 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
 *
 * A "match" is a data structure which acts like a mask or expression to match
 * certain windows or not. For example, when using commands, you can specify a
 * command like this: [title="*Firefox*"] kill. The title member of the match
 * data structure will then be filled and i3 will check each window using
 * match_matches_window() to find the windows affected by this command.
 *
 */
#include "all.h"

/* From sys/time.h, not sure if it's available on all systems. */
#define _i3_timercmp(a, b, CMP) \
    (((a).tv_sec == (b).tv_sec) ? ((a).tv_usec CMP(b).tv_usec) : ((a).tv_sec CMP(b).tv_sec))

/*
 * Initializes the Match data structure. This function is necessary because the
 * members representing boolean values (like dock) need to be initialized with
 * -1 instead of 0.
 *
 */
void match_init(Match *match) {
    memset(match, 0, sizeof(Match));
    match->urgent = U_DONTCHECK;
    match->window_mode = WM_ANY;
    /* we use this as the placeholder value for "not set". */
    match->window_type = UINT32_MAX;
}

/*
 * Check if a match is empty. This is necessary while parsing commands to see
 * whether the user specified a match at all.
 *
 */
bool match_is_empty(Match *match) {
    /* we cannot simply use memcmp() because the structure is part of a
     * TAILQ and I don't want to start with things like assuming that the
     * last member of a struct really is at the end in memory… */
    return (match->title == NULL &&
            match->mark == NULL &&
            match->application == NULL &&
            match->class == NULL &&
            match->instance == NULL &&
            match->window_role == NULL &&
            match->workspace == NULL &&
            match->machine == NULL &&
            match->urgent == U_DONTCHECK &&
            match->id == XCB_NONE &&
            match->window_type == UINT32_MAX &&
            match->con_id == NULL &&
            match->dock == M_NODOCK &&
            match->window_mode == WM_ANY &&
            match->match_all_windows == false);
}

/*
 * Copies the data of a match from src to dest.
 *
 */
void match_copy(Match *dest, Match *src) {
    memcpy(dest, src, sizeof(Match));

/* The DUPLICATE_REGEX macro creates a new regular expression from the
 * ->pattern of the old one. It therefore does use a little more memory then
 *  with a refcounting system, but it's easier this way. */
#define DUPLICATE_REGEX(field)                            \
    do {                                                  \
        if (src->field != NULL)                           \
            dest->field = regex_new(src->field->pattern); \
    } while (0)

    DUPLICATE_REGEX(title);
    DUPLICATE_REGEX(mark);
    DUPLICATE_REGEX(application);
    DUPLICATE_REGEX(class);
    DUPLICATE_REGEX(instance);
    DUPLICATE_REGEX(window_role);
    DUPLICATE_REGEX(workspace);
}

/*
 * Check if a match data structure matches the given window.
 *
 */
bool match_matches_window(Match *match, i3Window *window) {
    LOG("Checking window 0x%08x (class %s)\n", window->id, window->class_class);

#define GET_FIELD_str(field) (field)
#define GET_FIELD_i3string(field) (i3string_as_utf8(field))
#define CHECK_WINDOW_FIELD(match_field, window_field, type)                                       \
    do {                                                                                \
        if (match->match_field != NULL) {                                                         \
            const char *window_field_str = window->window_field == NULL                           \
                                               ? ""                                               \
                                               : GET_FIELD_##type(window->window_field);          \
            if (strcmp(match->match_field->pattern, "__focused__") == 0 &&                        \
                focused && focused->window && focused->window->window_field &&                    \
                strcmp(window_field_str, GET_FIELD_##type(focused->window->window_field)) == 0) { \
                LOG("window " #match_field " matches focused window\n");                          \
            } else if (regex_matches(match->match_field, window_field_str)) {                     \
                LOG("window " #match_field " matches (%s)\n", window_field_str);                  \
            } else {                                                                              \
                return false;                                                                     \
            }                                                                                \
        }                                                                                \
    } while (0)

    CHECK_WINDOW_FIELD(class, class_class, str);
    CHECK_WINDOW_FIELD(instance, class_instance, str);

    if (match->id != XCB_NONE) {
        if (window->id == match->id) {
            LOG("match made by window id (%d)\n", window->id);
        } else {
            LOG("window id does not match\n");
            return false;
        }
    }

    CHECK_WINDOW_FIELD(title, name, i3string);
    CHECK_WINDOW_FIELD(window_role, role, str);

    if (match->window_type != UINT32_MAX) {
        if (window->window_type == match->window_type) {
            LOG("window_type matches (%i)\n", match->window_type);
        } else {
            return false;
        }
    }

    CHECK_WINDOW_FIELD(machine, machine, str);

    Con *con = NULL;
    if (match->urgent == U_LATEST) {
        /* if the window isn't urgent, no sense in searching */
        if (window->urgent.tv_sec == 0) {
            return false;
        }
        /* if we find a window that is newer than this one, bail */
        TAILQ_FOREACH (con, &all_cons, all_cons) {
            if ((con->window != NULL) &&
                _i3_timercmp(con->window->urgent, window->urgent, >)) {
                return false;
            }
        }
        LOG("urgent matches latest\n");
    }

    if (match->urgent == U_OLDEST) {
        /* if the window isn't urgent, no sense in searching */
        if (window->urgent.tv_sec == 0) {
            return false;
        }
        /* if we find a window that is older than this one (and not 0), bail */
        TAILQ_FOREACH (con, &all_cons, all_cons) {
            if ((con->window != NULL) &&
                (con->window->urgent.tv_sec != 0) &&
                _i3_timercmp(con->window->urgent, window->urgent, <)) {
                return false;
            }
        }
        LOG("urgent matches oldest\n");
    }

    if (match->workspace != NULL) {
        if ((con = con_by_window_id(window->id)) == NULL)
            return false;

        Con *ws = con_get_workspace(con);
        if (ws == NULL)
            return false;

        if (strcmp(match->workspace->pattern, "__focused__") == 0 &&
            strcmp(ws->name, con_get_workspace(focused)->name) == 0) {
            LOG("workspace matches focused workspace\n");
        } else if (regex_matches(match->workspace, ws->name)) {
            LOG("workspace matches (%s)\n", ws->name);
        } else {
            return false;
        }
    }

    if (match->dock != M_DONTCHECK) {
        if ((window->dock == W_DOCK_TOP && match->dock == M_DOCK_TOP) ||
            (window->dock == W_DOCK_BOTTOM && match->dock == M_DOCK_BOTTOM) ||
            ((window->dock == W_DOCK_TOP || window->dock == W_DOCK_BOTTOM) &&
             match->dock == M_DOCK_ANY) ||
            (window->dock == W_NODOCK && match->dock == M_NODOCK)) {
            LOG("dock status matches\n");
        } else {
            LOG("dock status does not match\n");
            return false;
        }
    }

    if (match->mark != NULL) {
        if ((con = con_by_window_id(window->id)) == NULL)
            return false;

        bool matched = false;
        mark_t *mark;
        TAILQ_FOREACH (mark, &(con->marks_head), marks) {
            if (regex_matches(match->mark, mark->name)) {
                matched = true;
                break;
            }
        }

        if (matched) {
            LOG("mark matches\n");
        } else {
            LOG("mark does not match\n");
            return false;
        }
    }

    if (match->window_mode != WM_ANY) {
        if ((con = con_by_window_id(window->id)) == NULL) {
            return false;
        }

        switch (match->window_mode) {
            case WM_TILING_AUTO:
                if (con->floating != FLOATING_AUTO_OFF) {
                    return false;
                }
                break;
            case WM_TILING_USER:
                if (con->floating != FLOATING_USER_OFF) {
                    return false;
                }
                break;
            case WM_TILING:
                if (con_inside_floating(con) != NULL) {
                    return false;
                }
                break;
            case WM_FLOATING_AUTO:
                if (con->floating != FLOATING_AUTO_ON) {
                    return false;
                }
                break;
            case WM_FLOATING_USER:
                if (con->floating != FLOATING_USER_ON) {
                    return false;
                }
                break;
            case WM_FLOATING:
                if (con_inside_floating(con) == NULL) {
                    return false;
                }
                break;
            case WM_ANY:
                assert(false);
        }

        LOG("window_mode matches\n");
    }

    /* NOTE: See the comment regarding 'all' in match_parse_property()
     * for an explanation of why match_all_windows isn't explicitly
     * checked. */

    return true;
}

/*
 * Frees the given match. It must not be used afterwards!
 *
 */
void match_free(Match *match) {
    FREE(match->error);
    regex_free(match->title);
    regex_free(match->application);
    regex_free(match->class);
    regex_free(match->instance);
    regex_free(match->mark);
    regex_free(match->window_role);
    regex_free(match->workspace);
    regex_free(match->machine);
}

/*
 * Interprets a ctype=cvalue pair and adds it to the given match specification.
 *
 */
void match_parse_property(Match *match, const char *ctype, const char *cvalue) {
    assert(match != NULL);
    DLOG("ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);

    if (strcmp(ctype, "class") == 0) {
        regex_free(match->class);
        match->class = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "instance") == 0) {
        regex_free(match->instance);
        match->instance = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "window_role") == 0) {
        regex_free(match->window_role);
        match->window_role = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "con_id") == 0) {
        if (strcmp(cvalue, "__focused__") == 0) {
            match->con_id = focused;
            return;
        }

        long parsed;
        if (!parse_long(cvalue, &parsed, 0)) {
            ELOG("Could not parse con id \"%s\"\n", cvalue);
            match->error = sstrdup("invalid con_id");
        } else {
            match->con_id = (Con *)parsed;
            DLOG("id as int = %p\n", match->con_id);
        }
        return;
    }

    if (strcmp(ctype, "id") == 0) {
        long parsed;
        if (!parse_long(cvalue, &parsed, 0)) {
            ELOG("Could not parse window id \"%s\"\n", cvalue);
            match->error = sstrdup("invalid id");
        } else {
            match->id = parsed;
            DLOG("window id as int = %d\n", match->id);
        }
        return;
    }

    if (strcmp(ctype, "window_type") == 0) {
        if (strcasecmp(cvalue, "normal") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_NORMAL;
        } else if (strcasecmp(cvalue, "dialog") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_DIALOG;
        } else if (strcasecmp(cvalue, "utility") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_UTILITY;
        } else if (strcasecmp(cvalue, "toolbar") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_TOOLBAR;
        } else if (strcasecmp(cvalue, "splash") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_SPLASH;
        } else if (strcasecmp(cvalue, "menu") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_MENU;
        } else if (strcasecmp(cvalue, "dropdown_menu") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
        } else if (strcasecmp(cvalue, "popup_menu") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_POPUP_MENU;
        } else if (strcasecmp(cvalue, "tooltip") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_TOOLTIP;
        } else if (strcasecmp(cvalue, "notification") == 0) {
            match->window_type = A__NET_WM_WINDOW_TYPE_NOTIFICATION;
        } else {
            ELOG("unknown window_type value \"%s\"\n", cvalue);
            match->error = sstrdup("unknown window_type value");
        }

        return;
    }

    if (strcmp(ctype, "con_mark") == 0) {
        regex_free(match->mark);
        match->mark = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "title") == 0) {
        regex_free(match->title);
        match->title = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "urgent") == 0) {
        if (strcasecmp(cvalue, "latest") == 0 ||
            strcasecmp(cvalue, "newest") == 0 ||
            strcasecmp(cvalue, "recent") == 0 ||
            strcasecmp(cvalue, "last") == 0) {
            match->urgent = U_LATEST;
        } else if (strcasecmp(cvalue, "oldest") == 0 ||
                   strcasecmp(cvalue, "first") == 0) {
            match->urgent = U_OLDEST;
        }
        return;
    }

    if (strcmp(ctype, "workspace") == 0) {
        regex_free(match->workspace);
        match->workspace = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "machine") == 0) {
        regex_free(match->machine);
        match->machine = regex_new(cvalue);
        return;
    }

    if (strcmp(ctype, "tiling") == 0) {
        match->window_mode = WM_TILING;
        return;
    }

    if (strcmp(ctype, "tiling_from") == 0 &&
        cvalue != NULL &&
        strcmp(cvalue, "auto") == 0) {
        match->window_mode = WM_TILING_AUTO;
        return;
    }

    if (strcmp(ctype, "tiling_from") == 0 &&
        cvalue != NULL &&
        strcmp(cvalue, "user") == 0) {
        match->window_mode = WM_TILING_USER;
        return;
    }

    if (strcmp(ctype, "floating") == 0) {
        match->window_mode = WM_FLOATING;
        return;
    }

    if (strcmp(ctype, "floating_from") == 0 &&
        cvalue != NULL &&
        strcmp(cvalue, "auto") == 0) {
        match->window_mode = WM_FLOATING_AUTO;
        return;
    }

    if (strcmp(ctype, "floating_from") == 0 &&
        cvalue != NULL &&
        strcmp(cvalue, "user") == 0) {
        match->window_mode = WM_FLOATING_USER;
        return;
    }

    /* match_matches_window() only checks negatively, so match_all_windows
     * won't actually be used there, but that's OK because if no negative
     * match is found (e.g. because of a more restrictive criterion) the
     * return value of match_matches_window() is true.
     * Setting it here only serves to cause match_is_empty() to return false,
     * otherwise empty criteria rules apply, and that's not what we want. */
    if (strcmp(ctype, "all") == 0) {
        match->match_all_windows = true;
        return;
    }

    ELOG("Unknown criterion: %s\n", ctype);
}


text:
/**
 * External dependencies
 */
import { renderToStaticMarkup as _renderToStaticMarkup } from 'react-dom/server';
import type { ReactElement } from 'react';

/* eslint-disable no-console -- Deliberately overriding console.error  */

/**
 * Render a React element to static markup.
 *
 * Silences any `useLayoutEffect` warnings.
 *
 * Similar to `renderToString`, except this doesn't create extra DOM attributes
 * such as `data-reactid`, that React uses internally. This is useful if you want
 * to use React as a simple static page generator, as stripping away the extra
 * attributes can save lots of bytes.
 *
 * @param element React element.
 * @return Markup.
 */
function renderToStaticMarkup(
  element: ReactElement | ReactElement[] | null | string
): string {
  const originalConsoleError = console.error;
  console.error = function (error, ...args) {
    if (
      typeof error === 'string' &&
      !error.startsWith('Warning: useLayoutEffect does nothing on the server')
    ) {
      // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- OK to pass through here.
      originalConsoleError(error, ...args);
    }
  };

  const markup = _renderToStaticMarkup(element as ReactElement);

  console.error = originalConsoleError;

  return markup;
}

/* eslint-enable no-console -- Deliberately overriding console.error */

export default renderToStaticMarkup;


text:
package sparkz.utils

import scalaz.Monoid

case object StatCounterMonoid extends Monoid[StatCounter] {
  def zero: StatCounter = ZeroStatCounter

  def append(f1: StatCounter, f2: => StatCounter): StatCounter = f1 merge f2
}

object ZeroStatCounter extends StatCounter(0, 0.0, 0.0, Double.PositiveInfinity, Double.NegativeInfinity)

case object StatCounter {
  def apply(values: TraversableOnce[Double]): StatCounter = values.foldLeft(ZeroStatCounter: StatCounter)(_ merge _)

  def apply(value: Double): StatCounter = apply(List(value))

  implicit val monoid: Monoid[StatCounter] = StatCounterMonoid
}

case class StatCounter(n: Long, sum: Double, sos: Double, min: Double, max: Double) {
  def merge(other: StatCounter) = StatCounter(n + other.n, sum + other.sum, sos + other.sos,
    math.min(min, other.min), math.max(max, other.max))

  def merge(value: Double) = StatCounter(n + 1, sum + value, sos + (value * value),
    math.min(min, value), math.max(max, value))

  def merge(values: TraversableOnce[Double]): StatCounter = values.foldLeft(this)(_ merge _)

  def count = n

  def mean = sum / n

  def variance = if (n > 1) (sos - n * mean * mean) / (n - 1) else Double.NaN

  def stdev = math.sqrt(variance)

  def stderr = stdev / math.sqrt(n)

  override def toString = "(count: %d, mean: %f, stdev: %f, min: %f, max: %f)".format(count, mean, stdev, max, min)
}


text:
package com.albedinsky.android.fragment.examples.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.albedinsky.android.fragment.ActionBarFragment;
import com.albedinsky.android.fragment.examples.R;

import java.util.Random;

/**
 * @author Martin Albedinsky
 */
public final class ImageFragment extends ActionBarFragment {

	@SuppressWarnings("unused")
	private static final String TAG = "ImageFragment";

	private static final String BUNDLE_IMAGE_ORDINAL = "com.albedinsky.android.fragment.examples.fragment.ImageFragment.BUNDLE.ImageOrdinal";

	private enum Image {
		NATURE_01(R.drawable.nature_01),
		NATURE_02(R.drawable.nature_02),
		NATURE_03(R.drawable.nature_03),
		NATURE_04(R.drawable.nature_04),
		NATURE_05(R.drawable.nature_05),
		NATURE_06(R.drawable.nature_06),
		NATURE_07(R.drawable.nature_07),
		NATURE_08(R.drawable.nature_08),
		NATURE_09(R.drawable.nature_09),
		NATURE_10(R.drawable.nature_10),
		NATURE_11(R.drawable.nature_11),
		NATURE_12(R.drawable.nature_12);

		private static final Random RAND = new Random();

		private final int RES;

		private Image(int resID) {
			this.RES = resID;
		}

		static Image random() {
			return values()[RAND.nextInt(values().length)];
		}
	}

	private Image mImage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (savedInstanceState != null) {
			this.mImage = Image.values()[savedInstanceState.getInt(BUNDLE_IMAGE_ORDINAL, Image.NATURE_01.ordinal())];
		} else {
			this.mImage = Image.random();
		}
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt(BUNDLE_IMAGE_ORDINAL, mImage.ordinal());
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_image, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		final ImageView imageView = (ImageView) view.findViewById(R.id.fragment_image_image_view);
		imageView.setImageResource(mImage.RES);
	}
}


text:
//! Document feature set
//!
use libc::{c_char, c_int};
use std::cell::RefCell;
use std::collections::HashMap;
use std::ffi::{CStr, CString};
use std::fmt;
use std::ptr;
use std::rc::{Rc, Weak};
use std::str;

use crate::bindings::*;
use crate::readonly::RoNode;
use crate::tree::node::Node;

pub(crate) type DocumentRef = Rc<RefCell<_Document>>;
pub(crate) type DocumentWeak = Weak<RefCell<_Document>>;

#[derive(Debug, Copy, Clone, Default)]
/// Save Options for Document
pub struct SaveOptions {
  /// format save output
  pub format: bool,
  /// drop the xml declaration
  pub no_declaration: bool,
  /// no empty tags
  pub no_empty_tags: bool,
  /// disable XHTML1 specific rules
  pub no_xhtml: bool,
  /// force XHTML1 specific rules
  pub xhtml: bool,
  /// force XML serialization on HTML doc
  pub as_xml: bool,
  /// force HTML serialization on XML doc
  pub as_html: bool,
  /// format with non-significant whitespace
  pub non_significant_whitespace: bool,
}

#[derive(Debug)]
pub(crate) struct _Document {
  /// pointer to a libxml document
  pub(crate) doc_ptr: xmlDocPtr,
  /// hashed pointer-to-Node bookkeeping table
  nodes: HashMap<xmlNodePtr, Node>,
}

impl _Document {
  /// Internal bookkeeping function, so far only used by `Node::wrap`
  pub(crate) fn insert_node(&mut self, node_ptr: xmlNodePtr, node: Node) {
    self.nodes.insert(node_ptr, node);
  }
  /// Internal bookkeeping function, so far only used by `Node::wrap`
  pub(crate) fn get_node(&self, node_ptr: xmlNodePtr) -> Option<&Node> {
    self.nodes.get(&node_ptr)
  }
  /// Internal bookkeeping function
  pub(crate) fn forget_node(&mut self, node_ptr: xmlNodePtr) {
    self.nodes.remove(&node_ptr);
  }
}

/// A libxml2 Document
#[derive(Clone)]
pub struct Document(pub(crate) DocumentRef);

impl Drop for _Document {
  ///Free document when it goes out of scope
  fn drop(&mut self) {
    unsafe {
      if !self.doc_ptr.is_null() {
        xmlFreeDoc(self.doc_ptr);
      }
    }
  }
}

impl fmt::Display for Document {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    write!(f, "{}", self.to_string_with_options(SaveOptions::default()))
  }
}

impl Document {
  /// Creates a new empty libxml2 document
  pub fn new() -> Result<Self, ()> {
    unsafe {
      let c_version = CString::new("1.0").unwrap();
      let doc_ptr = xmlNewDoc(c_version.as_bytes().as_ptr());
      if doc_ptr.is_null() {
        Err(())
      } else {
        let doc = _Document {
          doc_ptr,
          nodes: HashMap::new(),
        };
        Ok(Document(Rc::new(RefCell::new(doc))))
      }
    }
  }

  /// Obtain the underlying libxml2 `xmlDocPtr` for this Document
  pub fn doc_ptr(&self) -> xmlDocPtr {
    self.0.borrow().doc_ptr
  }

  /// Creates a new `Document` from an existing libxml2 pointer
  pub fn new_ptr(doc_ptr: xmlDocPtr) -> Self {
    let doc = _Document {
      doc_ptr,
      nodes: HashMap::new(),
    };
    Document(Rc::new(RefCell::new(doc)))
  }

  pub(crate) fn null_ref() -> DocumentRef {
    Rc::new(RefCell::new(_Document {
      doc_ptr: ptr::null_mut(),
      nodes: HashMap::new(),
    }))
  }

  /// Write document to `filename`
  pub fn save_file(&self, filename: &str) -> Result<c_int, ()> {
    let c_filename = CString::new(filename).unwrap();
    unsafe {
      let retval = xmlSaveFile(c_filename.as_ptr(), self.doc_ptr());
      if retval < 0 {
        return Err(());
      }
      Ok(retval)
    }
  }

  pub(crate) fn register_node(&self, node_ptr: xmlNodePtr) -> Node {
    Node::wrap(node_ptr, &self.0)
  }

  /// Get the root element of the document
  pub fn get_root_element(&self) -> Option<Node> {
    unsafe {
      let node_ptr = xmlDocGetRootElement(self.doc_ptr());
      if node_ptr.is_null() {
        None
      } else {
        Some(self.register_node(node_ptr))
      }
    }
  }

  /// Get the root element of the document (read-only)
  pub fn get_root_readonly(&self) -> Option<RoNode> {
    unsafe {
      let node_ptr = xmlDocGetRootElement(self.doc_ptr());
      if node_ptr.is_null() {
        None
      } else {
        Some(RoNode(node_ptr))
      }
    }
  }

  /// Sets the root element of the document
  pub fn set_root_element(&mut self, root: &Node) {
    unsafe {
      xmlDocSetRootElement(self.doc_ptr(), root.node_ptr());
    }
    root.set_linked();
  }

  fn ptr_as_result(&mut self, node_ptr: xmlNodePtr) -> Result<Node, ()> {
    if node_ptr.is_null() {
      Err(())
    } else {
      let node = self.register_node(node_ptr);
      Ok(node)
    }
  }

  /// Import a `Node` from another `Document`
  pub fn import_node(&mut self, node: &mut Node) -> Result<Node, ()> {
    if !node.is_unlinked() {
      return Err(());
    }
    // Also remove this node from the prior document hash
    node
      .get_docref()
      .upgrade()
      .unwrap()
      .borrow_mut()
      .forget_node(node.node_ptr());

    let node_ptr = unsafe { xmlDocCopyNode(node.node_ptr(), self.doc_ptr(), 1) };
    node.set_linked();
    self.ptr_as_result(node_ptr)
  }

  /// Serializes the `Document` with options
  pub fn to_string_with_options(&self, options: SaveOptions) -> String {
    unsafe {
      // allocate a buffer to dump into
      let buf = xmlBufferCreate();
      let c_utf8 = CString::new("UTF-8").unwrap();
      let mut xml_options = 0;

      if options.format {
        xml_options += xmlSaveOption_XML_SAVE_FORMAT;
      }
      if options.no_declaration {
        xml_options += xmlSaveOption_XML_SAVE_NO_DECL;
      }
      if options.no_empty_tags {
        xml_options += xmlSaveOption_XML_SAVE_NO_EMPTY;
      }
      if options.no_xhtml {
        xml_options += xmlSaveOption_XML_SAVE_NO_XHTML;
      }
      if options.xhtml {
        xml_options += xmlSaveOption_XML_SAVE_XHTML;
      }
      if options.as_xml {
        xml_options += xmlSaveOption_XML_SAVE_AS_XML;
      }
      if options.as_html {
        xml_options += xmlSaveOption_XML_SAVE_AS_HTML;
      }
      if options.non_significant_whitespace {
        xml_options += xmlSaveOption_XML_SAVE_WSNONSIG;
      }

      let save_ctx = xmlSaveToBuffer(buf, c_utf8.as_ptr(), xml_options as i32);
      let _size = xmlSaveDoc(save_ctx, self.doc_ptr());
      let _size = xmlSaveClose(save_ctx);

      let result = xmlBufferContent(buf);
      let c_string = CStr::from_ptr(result as *const c_char);
      let node_string = c_string.to_string_lossy().into_owned();
      xmlBufferFree(buf);

      node_string
    }
  }

  /// Serializes a `Node` owned by this `Document`
  pub fn node_to_string(&self, node: &Node) -> String {
    unsafe {
      // allocate a buffer to dump into
      let buf = xmlBufferCreate();

      // dump the node
      xmlNodeDump(
        buf,
        self.doc_ptr(),
        node.node_ptr(),
        1, // level of indentation
        0, /* disable formatting */
      );
      let result = xmlBufferContent(buf);
      let c_string = CStr::from_ptr(result as *const c_char);
      let node_string = c_string.to_string_lossy().into_owned();
      xmlBufferFree(buf);

      node_string
    }
  }
  /// Serializes a `RoNode` owned by this `Document`
  pub fn ronode_to_string(&self, node: &RoNode) -> String {
    unsafe {
      // allocate a buffer to dump into
      let buf = xmlBufferCreate();

      // dump the node
      xmlNodeDump(
        buf,
        self.doc_ptr(),
        node.node_ptr(),
        1, // level of indentation
        0, /* disable formatting */
      );
      let result = xmlBufferContent(buf);
      let c_string = CStr::from_ptr(result as *const c_char);
      let node_string = c_string.to_string_lossy().into_owned();
      xmlBufferFree(buf);

      node_string
    }
  }

  /// Creates a node for an XML processing instruction
  pub fn create_processing_instruction(&mut self, name: &str, content: &str) -> Result<Node, ()> {
    unsafe {
      let c_name = CString::new(name).unwrap();
      let c_content = CString::new(content).unwrap();

      let node_ptr: xmlNodePtr = xmlNewDocPI(
        self.doc_ptr(),
        c_name.as_bytes().as_ptr(),
        c_content.as_bytes().as_ptr(),
      );
      if node_ptr.is_null() {
        Err(())
      } else {
        Ok(self.register_node(node_ptr))
      }
    }
  }

  /// Cast the document as a libxml Node
  pub fn as_node(&self) -> Node {
    // Note: this method is important to keep, as it enables certain low-level libxml2 idioms
    // In particular, method dispatch based on NodeType is only possible when the document can be cast as a Node
    //
    // Memory management is not an issue, as a document node can not be unbound/removed, and does not require
    // any additional deallocation than the Drop of a Document object.
    self.register_node(self.doc_ptr() as xmlNodePtr)
  }

  /// Duplicates the libxml2 Document into a new instance
  pub fn dup(&self) -> Result<Self, ()> {
    let doc_ptr = unsafe { xmlCopyDoc(self.doc_ptr(), 1) };
    if doc_ptr.is_null() {
      Err(())
    } else {
      let doc = _Document {
        doc_ptr,
        nodes: HashMap::new(),
      };
      Ok(Document(Rc::new(RefCell::new(doc))))
    }
  }

  /// Duplicates a source libxml2 Document into the empty Document self
  pub fn dup_from(&mut self, source: &Self) -> Result<(), ()> {
    if !self.doc_ptr().is_null() {
      return Err(());
    }

    let doc_ptr = unsafe { xmlCopyDoc(source.doc_ptr(), 1) };
    if doc_ptr.is_null() {
      return Err(());
    }
    self.0.borrow_mut().doc_ptr = doc_ptr;
    Ok(())
  }
}


text:
module PrefixRoutesWithLocale
  VERSION = "0.0.3"
end


text:
package org.strucdocs.component.security;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;
import org.strucdocs.component.user.UserRepository;
import org.strucdocs.model.User;

import java.util.Optional;

@Service
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class UserService {

    private final UserRepository userRepository;

    User getUser(String username, String name) {
        //byte[] picture = oAuth2RestTemplate.getForObject("https://graph.facebook.com/me/picture", byte[].class);
        return Optional.ofNullable(userRepository.findByUsername(username))
            .orElse(userRepository.save(User.builder().username(username).name(name).build()));
    }
}


text:
exercice02-sio2109

4 Questions

A minimal command-line application.


text:
import { DeploymentTrackerPage } from './app.po';

describe('edureka-certification App', () => {
  let page: DeploymentTrackerPage;

  beforeEach(() => {
    page = new DeploymentTrackerPage();
  });

  it('should display message saying app works', () => {
    page.navigateTo();
    expect(page.getParagraphText()).toEqual('app works!');
  });
});


text:
<!DOCTYPE html>

<link href='../../dist/fullcalendar.css' rel='stylesheet' />
<link href='../../dist/fullcalendar.print.css' rel='stylesheet' media='print' />


text:
using json = nlohmann::json;

int main()
{
    // tagged byte string
    std::vector<std::uint8_t> vec = {{0xd8, 0x42, 0x44, 0xcA, 0xfe, 0xba, 0xbe}};

    // cbor_tag_handler_t::error throws
    try
    {
        auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error);
    }
    catch (json::parse_error& e)
    {
        std::cout << e.what() << std::endl;
    }

    // cbor_tag_handler_t::ignore ignores the tag
    auto b_ignore_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::ignore);
    std::cout << b_ignore_tag << std::endl;

    // cbor_tag_handler_t::store stores the tag as binary subtype
    auto b_store_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::store);
    std::cout << b_store_tag << std::endl;
}


text:
package javax.swing;

public class JComponent extends Container {
  public static final int WHEN_FOCUSED = 0;
  public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1;
  public static final int WHEN_IN_FOCUSED_WINDOW = 2;

  public Border getBorder();
  public void setBorder(Border border);

  public void setOpaque(boolean isOpaque);
  public void setToolTipText(String text);

  public final InputMap getInputMap(int condition);
  public final void setInputMap(int condition, InputMap map);

  public final ActionMap getActionMap();
  public final void setActionMap(ActionMap am);

  public boolean requestFocusInWindow();
}


text:
static const uint32_t clear_dl_snippet[] =
{
    // set the background colour to dark grey and clear the screen
    FT81X_DL_CMD_CLEAR_COLOUR_RGB(0,0,0),
    FT81X_DL_CMD_CLEAR(1,1,1),
};

ft81x_result test2_logo(FT81X_Handle *handle)
{
    ft81x_result res;

    res = ft81x_coproc_cmd_logo(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_logo failed with %u\n", res);
        return res;
    }
    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }
    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_compressed_images(FT81X_Handle *handle)
{
    ft81x_result res;

    // ----------------------------------------------------------
    // load our resources into g RAM
    // ----------------------------------------------------------
    // first is the L8 image
    FT81X_Image_Handle cat_l8_compressed_image_handle;
    res = ft81x_image_manager_load_image(handle, &cat_l8_compressed_image_properties, &cat_l8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_load_image failed with %u\n", res);
        return res;
    }

    // then the argb1555 image
    FT81X_Image_Handle cat_argb1555_compressed_image_handle;
    res = ft81x_image_manager_load_image(handle, &cat_argb1555_compressed_image_properties, &cat_argb1555_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_load_image failed with %u\n", res);
        return res;
    }

    // then the paletted8 image
    FT81X_Image_Handle cat_paletted8_compressed_image_handle;
    res = ft81x_image_manager_load_image(handle, &cat_paletted8_compressed_image_properties, &cat_paletted8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_load_image failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Build and display the display list
    // ----------------------------------------------------------
    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // initialise the L8 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_l8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // initialise the argb1555 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_argb1555_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // initialise the paletted8 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_paletted8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // draw L8 image
    res = ft81x_image_manager_send_image_draw_dl(handle,
                                                 &cat_l8_compressed_image_handle,
                                                 FT81X_BITMAP_FILTER_NEAREST,
                                                 160-(cat_l8_compressed_image_properties.width/2),
                                                 240-(cat_l8_compressed_image_properties.height/2),
                                                 NULL);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl failed with %u\n", res);
        return res;
    }

    // draw ARGB1555 image
    res = ft81x_image_manager_send_image_draw_dl(handle,
                                                 &cat_argb1555_compressed_image_handle,
                                                 FT81X_BITMAP_FILTER_NEAREST,
                                                 0, 0,
                                                 NULL);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl failed with %u\n", res);
        return res;
    }

    // draw paletted8 image
    // (note saves the context on the stack and restores it)
    res = ft81x_image_manager_send_image_draw_dl(handle,
                                                 &cat_paletted8_compressed_image_handle,
                                                 FT81X_BITMAP_FILTER_NEAREST,
                                                 162, 270,
                                                 NULL);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_text(FT81X_Handle *handle)
{
    ft81x_result res;

    // ----------------------------------------------------------
    // load our custom font into g RAM
    // ----------------------------------------------------------
    FT81X_Font_Handle blink_font_handle;
    res = ft81x_text_manager_load_custom_font(handle, &blink_font_l2_raw_font_properties, &blink_font_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_load_custom_font failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Get font handles for inbuilt fonts
    // ----------------------------------------------------------
    FT81X_Font_Handle inbuilt_31_font_handle;
    res = ft81x_text_manager_get_font_handle_for_inbuilt_font(handle, &inbuilt_31_font_handle, 31);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_get_font_handle_for_inbuilt_font failed with %u\n", res);
        return res;
    }
    FT81X_Font_Handle inbuilt_34_font_handle;
    res = ft81x_text_manager_get_font_handle_for_inbuilt_font(handle, &inbuilt_34_font_handle, 34);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_get_font_handle_for_inbuilt_font failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Build and display the display list
    // ----------------------------------------------------------
    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // initialise the custom font
    // note: don't need to init inbuilt fonts
    // the API lets you, it just won't do anything
    res = ft81x_text_manager_send_font_init_dl(handle,
                                               &blink_font_handle,
                                               FT81X_BITMAP_FILTER_NEAREST,
                                               FT81X_BITMAP_WRAP_BORDER,
                                               FT81X_BITMAP_WRAP_BORDER);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_send_font_init_dl failed with %u\n", res);
        return res;
    }

    // change the colour for the folowwing text
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_COLOUR_RGB(255, 0, 0));
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // show some text
    res = ft81x_text_manager_write_text(handle, &inbuilt_31_font_handle, 10, 30, FT81X_TEXT_COORDS_TOP_LEFT, "Test 2");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_text failed with %u\n", res);
        return res;
    }

    // show some numbers
    res = ft81x_text_manager_write_unsigned_number(handle, &inbuilt_31_font_handle, 10, 100, FT81X_TEXT_COORDS_TOP_LEFT, 0xFFFFFFFF);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_unsigned_number failed with %u\n", res);
        return res;
    }

    res = ft81x_text_manager_write_signed_number(handle, &inbuilt_31_font_handle, 10, 150, FT81X_TEXT_COORDS_TOP_LEFT, (int32_t)0xFFFFFFFF);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_signed_number failed with %u\n", res);
        return res;
    }

    // custom font text (note I replaced the data for ~ with a smiley)
    res = ft81x_text_manager_write_text(handle, &blink_font_handle, 10, 200, FT81X_TEXT_COORDS_TOP_LEFT, "Custom Font -> ~");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_text failed with %u\n", res);
        return res;
    }

    // numbers with custom font
    res = ft81x_text_manager_write_unsigned_number(handle, &blink_font_handle, 10, 230, FT81X_TEXT_COORDS_TOP_LEFT, (uint32_t)-1);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_unsigned_number failed with %u\n", res);
        return res;
    }

    res = ft81x_text_manager_write_signed_number(handle, &blink_font_handle, 10, 260, FT81X_TEXT_COORDS_TOP_LEFT, -1);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_signed_number failed with %u\n", res);
        return res;
    }

    res = ft81x_text_manager_write_unsigned_number(handle, &blink_font_handle, 10, 290, FT81X_TEXT_COORDS_TOP_LEFT, 1337);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_unsigned_number failed with %u\n", res);
        return res;
    }

    // test using inbuilt font 34 - note this has to be remapped
    // to a different bitmap_handle as only bitmap handles 0 - 31
    // are supported by the FT81X
    res = ft81x_text_manager_write_unsigned_number(handle, &inbuilt_34_font_handle, 10, 330, FT81X_TEXT_COORDS_TOP_LEFT, 34);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_text_manager_write_unsigned_number failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_buttons(FT81X_Handle *handle)
{
    ft81x_result res;

    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // draw a default button
    res = ft81x_coproc_cmd_button(handle, 10, 10, 200, 100, 24, 0, "button1");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_button failed with %u\n", res);
        return res;
    }

    // change the fg colour to red
    res = ft81x_coproc_cmd_fgcolour(handle, 255, 0, 0);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_fgcolour failed with %u\n", res);
        return res;
    }

    // draw a flat button
    res = ft81x_coproc_cmd_button(handle, 10, 120, 200, 100, 24, FT81X_COPROC_OPTION_FLAT, "flat button");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_button failed with %u\n", res);
        return res;
    }

    // change the fg colour to dark yellow
    res = ft81x_coproc_cmd_fgcolour(handle, 32, 32, 0);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_fgcolour failed with %u\n", res);
        return res;
    }

    // set the gradient colour to blue
    res = ft81x_coproc_cmd_gradcolour(handle, 0, 0, 255);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_gradcolour failed with %u\n", res);
        return res;
    }

    // draw another button
    res = ft81x_coproc_cmd_button(handle, 10, 220, 250, 200, 28, 0, "button 3 with gradient");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_button failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_clocks_and_guages(FT81X_Handle *handle)
{
    ft81x_result res;

    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // draw a default clock
    res = ft81x_coproc_cmd_clock(handle, 50, 50, 50, 0, 6, 30, 15, 500);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // draw a default gauge
    res = ft81x_coproc_cmd_gauge(handle, 250, 50, 50, 0, 5, 2, 75, 100);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // change the bg colour to green
    res = ft81x_coproc_cmd_bgcolour(handle, 0, 255, 0);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_bgcolour failed with %u\n", res);
        return res;
    }

    // draw a flat clock with no ticks
    res = ft81x_coproc_cmd_clock(handle, 50, 170, 60, FT81X_COPROC_OPTION_FLAT | FT81X_COPROC_OPTION_NOTICKS, 3, 45, 35, 100);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // draw a flat gauge with no ticks
    res = ft81x_coproc_cmd_gauge(handle, 250, 170, 60, FT81X_COPROC_OPTION_FLAT | FT81X_COPROC_OPTION_NOTICKS, 5, 1, 25, 100);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // draw a clock with no hands and no background
    res = ft81x_coproc_cmd_clock(handle, 100, 300, 90, FT81X_COPROC_OPTION_NOBACK | FT81X_COPROC_OPTION_NOHANDS, 3, 45, 35, 100);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // draw a gauge with no pointer and no background
    res = ft81x_coproc_cmd_gauge(handle, 250, 300, 90, FT81X_COPROC_OPTION_NOPOINTER | FT81X_COPROC_OPTION_NOBACK, 2, 10, 25, 100);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_keys_dials_toggles(FT81X_Handle *handle)
{
    ft81x_result res;

    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // draw some keys
    res = ft81x_coproc_cmd_keys(handle, 50, 50, 270, 50, 23, 'a', "aaAbBcC");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // draw a dial
    res = ft81x_coproc_cmd_dial(handle, 80, 240, 80, 0, 0x2000);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_dial failed with %u\n", res);
        return res;
    }

    // draw a toggle
    res = ft81x_coproc_cmd_toggle(handle, 50, 330, 80, 23, 0, 0, "off\xffon");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_toggle failed with %u\n", res);
        return res;
    }

    // change the fg colour to red
    res = ft81x_coproc_cmd_fgcolour(handle, 255, 0, 0);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_fgcolour failed with %u\n", res);
        return res;
    }

    // change the bg colour to white
    res = ft81x_coproc_cmd_bgcolour(handle, 255, 255, 255);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_bgcolour failed with %u\n", res);
        return res;
    }

    // set the text colour to black
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_COLOUR_RGB(0,0,0));
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // change the grad colour to blue
    res = ft81x_coproc_cmd_gradcolour(handle, 0, 0, 255);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_gradcolour failed with %u\n", res);
        return res;
    }

    // draw some keys
    res = ft81x_coproc_cmd_keys(handle, 50, 110, 250, 50, 23, FT81X_COPROC_OPTION_CENTRE | 'B', "aAbBcC123");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_clock failed with %u\n", res);
        return res;
    }

    // draw a flat dial
    res = ft81x_coproc_cmd_dial(handle, 240, 240, 80, FT81X_COPROC_OPTION_FLAT, 6000);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_dial failed with %u\n", res);
        return res;
    }

    // draw a flat toggle
    res = ft81x_coproc_cmd_toggle(handle, 190, 330, 80, 23, 0, 1, "off\xffon");
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_toggle failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_gradient(FT81X_Handle *handle)
{
    ft81x_result res;

    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // show a gradient
    res = ft81x_coproc_cmd_gradient(handle, 200, 100, 255, 0, 0, 300, 400, 0, 0, 255);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_gradient failed with %u\n", res);
        return res;
    }

#pragma message WARN("TODO: add support for scissor commands then improve test2_gradient()")

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_progress_scrollbars_sliders(FT81X_Handle *handle)
{
    ft81x_result res;

    for (int i = 0; i <= 100; i++)
    {
        // reset the co-proc to it's default state
        res = ft81x_coproc_cmd_coldstart(handle);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
            return res;
        }

        // clear the screen
        res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
            return res;
        }

        // show a progress bar
        res = ft81x_coproc_cmd_progress(handle, 50, 50, 220, 30, 0, i, 100);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_progress failed with %u\n", res);
            return res;
        }

        // show a horizontal scrollbar
        res = ft81x_coproc_cmd_scrollbar(handle, 0, 460, 320, 20, 0, i, 10, 110);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_scrollbar failed with %u\n", res);
            return res;
        }

        // show a vertical scrollbar
        res = ft81x_coproc_cmd_scrollbar(handle, 300, 0, 20, 480, 0, i, 30, 130);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_scrollbar failed with %u\n", res);
            return res;
        }

        // show a slider
        res = ft81x_coproc_cmd_slider(handle, 50, 150, 100, 40, 0, i, 100);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_slider failed with %u\n", res);
            return res;
        }

        // show the current value of i
        res = ft81x_coproc_cmd_number(handle, 100, 300, 31, FT81X_COPROC_OPTION_RIGHTX, i);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_number failed with %u\n", res);
            return res;
        }

        // display it
        res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
            return res;
        }

        // write everything to the DL ram and then swap it in
        res = ft81x_graphics_engine_end_display_list(handle);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
            return res;
        }

        Sleep(100);
    }
    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_transformations(FT81X_Handle *handle)
{
    ft81x_result res;

    // ----------------------------------------------------------
    // load our resources into g RAM
    // ----------------------------------------------------------
    FT81X_Image_Handle nyam_rgb565_compressed_image_handle;
    res = ft81x_image_manager_load_image(handle, &nyam_rgb565_compressed_image_properties, &nyam_rgb565_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_load_image failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Build and display the display list
    // ----------------------------------------------------------
    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // initialise the rgb565 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &nyam_rgb565_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // draw rgb565 image
    res = ft81x_image_manager_send_image_draw_dl(handle,
                                                 &nyam_rgb565_compressed_image_handle,
                                                 FT81X_BITMAP_FILTER_NEAREST,
                                                 0, 0,
                                                 NULL);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl failed with %u\n", res);
        return res;
    }

    // draw the rgb565 image again this time twice as big
    FT81X_Image_Transform tform =
    {
        .scale          = 1,        // scale by 3/4 in both dimensions
        .scale_x        = 2,
        .scale_y        = 2,
    };
    res = ft81x_image_manager_send_image_draw_dl(handle,
                                                 &nyam_rgb565_compressed_image_handle,
                                                 FT81X_BITMAP_FILTER_NEAREST,
                                                 100, 0,
                                                 &tform);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl failed with %u\n", res);
        return res;
    }

    // again buut half the original size
    tform.scale_x = 0.5;
    tform.scale_y = 0.5;
    res = ft81x_image_manager_send_image_draw_dl(handle,
                                                 &nyam_rgb565_compressed_image_handle,
                                                 FT81X_BITMAP_FILTER_NEAREST,
                                                 0, 50,
                                                 &tform);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(3000);

    return FT81X_RESULT_OK;
}

ft81x_result test2_spinners(FT81X_Handle *handle)
{
    ft81x_result res;

    uint8_t colours[4][3] =
    {
        { 255, 0, 0 },
        { 0, 255, 0 },
        { 0, 0, 255 },
        { 255, 255, 255 },
    };

    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    for (int i = 0; i < 4; i++)
    {
        // clear the screen
        res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
            return res;
        }

        // put something on the screen
        uint32_t draw_lines[] =
        {
            FT81X_DL_CMD_COLOUR_RGB(255, 255, 255),
            FT81X_DL_CMD_LINE_WIDTH(5 * 16),
            FT81X_DL_CMD_BEGIN(FT81X_PRIMITIVE_LINES),
                FT81X_DL_CMD_VERTEX2II(0, 0, 0, 0),
                FT81X_DL_CMD_VERTEX2II(320, 480, 0, 0),
                FT81X_DL_CMD_VERTEX2II(320, 0, 0, 0),
                FT81X_DL_CMD_VERTEX2II(0, 480, 0, 0),
                FT81X_DL_CMD_VERTEX2II(0, 0, 0, 0),
            FT81X_DL_CMD_END(),
        };
        res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(draw_lines), draw_lines);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
            return res;
        }

        // set the spinner colour
        res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_COLOUR_RGB(colours[i][0],colours[i][1],colours[i][2]));
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
            return res;
        }

        // start a spinner
        res = ft81x_coproc_cmd_spinner(handle, 160, 240, i, 1);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_spinner failed with %u\n", res);
            return res;
        }

        // display it
        res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
            return res;
        }

        // write everything to the DL ram and then swap it in
        res = ft81x_graphics_engine_end_display_list(handle);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
            return res;
        }

        Sleep(2000);

        // stop it
        res = ft81x_coproc_cmd_stop(handle);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_coproc_cmd_stop failed with %u\n", res);
            return res;
        }

        res = ft81x_graphics_engine_flush_and_synchronise(handle);
        if (res != FT81X_RESULT_OK)
        {
            printf("ft81x_graphics_engine_flush_and_synchronise failed with %u\n", res);
            return res;
        }

        Sleep(1000);
    }

    return FT81X_RESULT_OK;
}

ft81x_result test2_screensaver(FT81X_Handle *handle)
{
    ft81x_result res;

    // ----------------------------------------------------------
    // load our resources into g RAM
    // ----------------------------------------------------------
    // The l8 image
    FT81X_Image_Handle cat_l8_compressed_image_handle;
    res = ft81x_image_manager_load_image(handle, &cat_l8_compressed_image_properties, &cat_l8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_load_image failed with %u\n", res);
        return res;
    }

    // The paletted8 image
    FT81X_Image_Handle cat_paletted8_compressed_image_handle;
    res = ft81x_image_manager_load_image(handle, &cat_paletted8_compressed_image_properties, &cat_paletted8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_load_image failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Build and display the display list
    // ----------------------------------------------------------
    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    res = ft81x_coproc_cmd_screensaver(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_screensaver failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // initialise the l8 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_l8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // initialise the paletted8 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_paletted8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // because we are using vertex2f (see CMD_SCREENSAVER)
    // we have to specify the bitmap source first
    res = ft81x_image_manager_set_active_bitmap(handle, &cat_l8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_set_active_bitmap failed with %u\n", res);
        return res;
    }

    // draw l8 image using macro_0
    // the co-proc replaces macro_0 with vertex2f
    // due to the CMD_SCREENSAVER above
    res = ft81x_image_manager_send_image_draw_dl_with_macro_0(handle,
                                                              &cat_l8_compressed_image_handle,
                                                              FT81X_BITMAP_FILTER_NEAREST,
                                                              NULL);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl_with_macro_0 failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(5000);

    // stop it
    res = ft81x_coproc_cmd_stop(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_stop failed with %u\n", res);
        return res;
    }

    // reset the co-proc to it's default state
    res = ft81x_coproc_cmd_coldstart(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_coldstart failed with %u\n", res);
        return res;
    }

    res = ft81x_coproc_cmd_screensaver(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_screensaver failed with %u\n", res);
        return res;
    }

    // clear the screen
    res = ft81x_graphics_engine_write_display_list_snippet(handle, sizeof(clear_dl_snippet), clear_dl_snippet);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_snippet failed with %u\n", res);
        return res;
    }

    // initialise the l8 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_l8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // initialise the paletted8 image in the DL
    res = ft81x_image_manager_send_image_init_dl(handle,
                                                 &cat_paletted8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_init_dl failed with %u\n", res);
        return res;
    }

    // because we are using vertex2f (see CMD_SCREENSAVER)
    // we have to specify the bitmap source first
    res = ft81x_image_manager_set_active_bitmap(handle, &cat_paletted8_compressed_image_handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_set_active_bitmap failed with %u\n", res);
        return res;
    }

    // draw paletted8 image using macro_0
    // the co-proc replaces macro_0 with vertex2f
    // due to the CMD_SCREENSAVER above
    res = ft81x_image_manager_send_image_draw_dl_with_macro_0(handle,
                                                              &cat_paletted8_compressed_image_handle,
                                                              FT81X_BITMAP_FILTER_NEAREST,
                                                              NULL);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_image_manager_send_image_draw_dl_with_macro_0 failed with %u\n", res);
        return res;
    }

    // display it
    res = ft81x_graphics_engine_write_display_list_cmd(handle, FT81X_DL_CMD_DISPLAY());
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_write_display_list_cmd failed with %u\n", res);
        return res;
    }

    // write everything to the DL ram and then swap it in
    res = ft81x_graphics_engine_end_display_list(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_end_display_list failed with %u\n", res);
        return res;
    }

    Sleep(5000);

    // stop it
    res = ft81x_coproc_cmd_stop(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_coproc_cmd_stop failed with %u\n", res);
        return res;
    }

    res = ft81x_graphics_engine_flush_and_synchronise(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("ft81x_graphics_engine_flush_and_synchronise failed with %u\n", res);
        return res;
    }

    return FT81X_RESULT_OK;
}

ft81x_result test2(FT81X_Handle *handle)
{
    ft81x_result res;

    // ----------------------------------------------------------
    // Display some text
    // ----------------------------------------------------------
    res = test2_text(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_text failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display the FTDI logo animation
    // ----------------------------------------------------------
    res = test2_logo(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_logo failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display some compressed images
    // ----------------------------------------------------------
    res = test2_compressed_images(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_compressed_images failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display some buttons
    // ----------------------------------------------------------
    res = test2_buttons(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_buttons failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display some clocks and guages
    // ----------------------------------------------------------
    res = test2_clocks_and_guages(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_clocks_and_guages failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display some keys, dials and toggles
    // ----------------------------------------------------------
    res = test2_keys_dials_toggles(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_keys_dials_toggles failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display a gradient
    // ----------------------------------------------------------
    res = test2_gradient(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_gradient failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Display a progress bar, some scrollbars and sliders
    // ----------------------------------------------------------
    res = test2_progress_scrollbars_sliders(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_progress_scrollbars_sliders failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Demonstrtate transformations
    // ----------------------------------------------------------
    res = test2_transformations(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_transformations failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Demonstrtate spinners
    // ----------------------------------------------------------
    res = test2_spinners(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_spinners failed with %u\n", res);
        return res;
    }

    // ----------------------------------------------------------
    // Demonstrtate screensaver
    // ----------------------------------------------------------
    res = test2_screensaver(handle);
    if (res != FT81X_RESULT_OK)
    {
        printf("test2_screensaver failed with %u\n", res);
        return res;
    }

    return FT81X_RESULT_OK;
}