What is a JSON feed? Learn more

JSON Feed Viewer

Browse through the showcased feeds, or enter a feed URL below.

Now supporting RSS and Atom feeds thanks to Andrew Chilton's feed2json.org service

CURRENT FEED

Wesley Hill

software engineer & (hobbyist) animator. Blogging about reading, writing and executing code. (mostly writing)

A feed by Wesley Hill

JSON


Custom Callback Notifications in Autodesk 3DS Max

Permalink - Posted on 2019-11-29 00:00

Discovering new things is awesome, especially by accident. This was the case when I was working with the Autodesk 3ds Max .NET SDK, as I was tasked to add a feature that required using a custom callback function.

Skip to the solution & code examples if you’re already familiar with 3ds Max.

Un(document)ed Territory

If you’ve worked with Autodesk 3ds Max long enough, you would know you can use MaxScript, Python, C# and C++ to interface with it. Unlike the former two languages, C++ & C# uses the 3ds Max SDK, which comes with extremely sparse documentation online, resulting in you trawling through a revolving door of redirects or 404 pages galore.

The only way to get code samples is to install the SDK from the 3ds Max disk image (I didn’t have this available and I strongly recommend doing this). But even then, the SDK has no .NET samples. Luckily, the C# codebase is structured nicely and well commented; a nice substitute.

Since the tool I worked on is written in C#, the DLL needed to use these notifications are in Autodesk.Max.dll (found in the installation directory) one can use a .NET disassembler to pry into the classes, methods, constants, etc. I stumbled across SystemNotificationCode.cs, a list of notification events defined in 3ds Max. Here is a small example on how to use it and below is a truncated list of example notifications (the full list is here)

public enum SystemNotificationCode : uint
{
    UnitsChange = 1,
    TimeunitsChange = 2,
    ViewportChange = 3,
    ...
    LayerHiddenStateChanged = 8193,
    LayerRenamed = 8194,
    InternalUseStart = 1879048192
}

If you look closely at that list, you will notice Custom1 to Custom7 notifications.

...
Custom1 = 4098,
Custom2 = 4099,
Custom3 = 4100,
Custom4 = 4101,
Custom5 = 4102,
Custom6 = 4103,
Custom7 = 4104,
...

It turns out you can use these as custom callback notifications. I was looking for documentation on this in the SDK and on Google. There really wasn’t anything related to calling these custom notifications. I had a hunch that these notifications are also built into 3ds Max, so it was a case of just trying it out.

Calling the Custom Callback Notification

To see what this looks like in action, below is a list of event notifications tied to their respective functions.

For example if you reset the whole scene in 3DS Max, SystemPreReset will be triggered before the scene gets reset and SystemPostReset will be triggered after the scene gets reset, causing our nicely named notifications onSystemPreReset and onSystemPostReset to be called.

To trigger the custom system notification CustomN, we have to turn to MaxScript for help. A very handy property of MaxScript is that it can interoperate with Python and .NET.


bn = (dotNetClass "Autodesk.Max.GlobalInterface").Instance.BroadcastNotification
bn (dotNetClass "Autodesk.Max.SystemNotificationCode").Custom3

Once this code runs, any function that is hooked onto Custom3 would execute. This function can be in MaxScript, Python, C# or C++.

That’s it really…

Code Examples

You’re not leaving empty handed! I’ve taken it upon myself to write 4 basic examples of calling custom notifications in MaxScript, Python, C# and C++; something akin to samples Autodesk should have provided.

Try it out yourself! the code is over on GitHub.

Instructions for installation and how to build/run the project are on the README.

(Or if you’re lazy just download the DLL (C#) / DLU (C++) from the releases section and follow the instructions.


Alternatives to JSON Web Tokens (JWT)

Permalink - Posted on 2018-12-31 00:00

Back in around November of 2018, I gave a talk at London Gophers Meetup @ River Island about alternatives to JWT tokens.

If you’re in a hurry or want a TL;DR/DW, jump straight to the alternatives or read on if you want to read my motivation for doing the talk.

You can see the video and slides below: (note requires JavaScript):

Slides

Video (10 mins)


Motivation

The gist of why I did this talk is the fact that on Reddit, Medium and especially on HN, I see the following discussion on JWT’s:

A: Don't use JWT.
B: What are some alternatives to JWT?

Pretty much the discussion diverges into an array of setups of how to handle JWT situations such as token revocation, blacklisting tokens, etc for which I have little time for reading threads of different JWT setups. You only have to look at few of the comments on these to get my point.

From what I see, the reasons JWTs are frowned upon is that:

That being said, I am sure there are many more reasons but those two are the most common ones.

Alternatives?

The alternatives shown in my lightning talk were:

These three alternatives have one shared advantage over JWT, they don’t allow the user to change the algorithm and use best practices of modern cryptography. You can also see implementations of these alternatives in your favourite language.

The individual advantages of each alternative token are on the last page of my slide (note requires JavaScript):

Who’s using them?

Good question! this section will be continuously updated until I lose count, but here are a few:


Acknowledgements

I would like to thank Mika Tuupola, Scott Arciszewski and Paul Jolly for checking over my slides and the London Gophers Meetup organisers + River Island for having me.


Drawpile on Haiku!

Permalink - Posted on 2018-08-18 23:00

A few months ago, I stumbled across an interesting piece of software called Drawpile. It is an open source drawing program which allows users anywhere in the world to draw together. It turns out (and I’m glad) that this program is available on Windows, Mac and GNU/Linux.

But why stop at those three? I had the idea of porting Drawpile to Haiku as a bonus. For those who don’t know what Haiku is:

Haiku is an open-source operating system that specifically targets personal computing. Inspired by the BeOS, Haiku is fast, simple to use, easy to learn and yet very powerful. – haiku-os.org

BeOS, developed by Be Inc., has been long discontinued and Haiku supports most (if not all) of it’s features. You can find out more through their FAQ. Haiku has it’s own package manager called HaikuDepot (think of it like an App Store) where you can download applications for Haiku such as: Telegram, Blender, LibreOffice and Transmission. For developers: Qt, Vim, Emacs, Python, Rust and Swift etc..

Porting Drawpile to Haiku required a few dependencies that already existed on Haiku such as Qt5, libsodium and KF5 KArchive. I wrote a buildscript (called a recipe) which builds Drawpile into a nice package for HaikuDepot. A few changes to the buildscript later and Drawpile compliled on Haiku!

With the installation complete, I launched it from Applications / Drawpile in the menu screen and the GUI opened with no issues and drawing works well too.

I connected to a random Drawpile server to test if it worked without issues, turns out it does quite well. Note that I’m using VirtualBox to run Drawpile and it’s a bit cumbersome to use under a VM, but you get the idea.

I made a pull request (PR) to HaikuPorts (the recipe repository for haiku packages) to include Drawpile into Haiku, you should see it in the HaikuDepot once the PR has merged. If you want to try it out, you can download the Drawpile package with previous versions directly from HaikuDepot.

If you’d like to contribute more software to Haiku, I recommend starting at the HaikuPorts repository wiki.

HaikuPorts Wiki

Building packages with haikuporter


Writing GUI apps using the Red Programming Language

Permalink - Posted on 2017-12-19 00:00

Russian Translation by HTR

Chinese Translation by oschina.net

Uzbek Translation by vectorified.com

After trying (and failing) to wrap “executable” ducktape around a Python script using PyInstaller on Windows, The class of programming languages which now usually pique my interest have the following attributes:

  • Static binary compilation. (producing a binary, not running bytecode i.e Java, Python)
  • Fast.
  • Cross Platform. (Windows, Mac, Linux, *BSD and/or Haiku (Bonus) )

Having picked up Go three years ago for this purpose, (started developing an app with it) I can guarantee that Go binaries work across multiple platforms through cross compilation. Other languages such as Crystal and Rust also tick the boxes above, but both were not stable at the time. Today, I’m exploring options for native cross platform GUIs1.

There have been lots of “modern desktop applications” being built with Electron. This allows programmers to build desktop applications with HTML, CSS and JavaScript. Sounds awesome right? Well…

While Electron is easier, faster to market and cost effective for programmers, Electron is notorious for the sheer amount of bloat it carries in binary size and in RAM usage2. You may have come across posts lamenting the use of it, to the point that bashing Electron is almost guaranteed in an online tech forum if any application dares to use it.

To your disappointment, this is not one of these posts. Qt and GTK+ are interesting alternatives, I even plan to use them myself. However, both are not as quick to develop in as Electron is. Can we have both? A native cross platform GUI that is also faster to develop in? Enter Red.

Red

Red is a next-generation programming language strongly inspired by Rebol.”

Red was made largely because Rebol was proprietary, closed source software (That is until in 2012, Rebol 3 was made open source). Both languages have a great GUI system (which we will get into), the difference Red makes is that it can be used for systems programmming with a DSL called Red/System and the compiler is amazingly less than 2MB. You can find out more about Red here and you can download it here.

GUI

Here is a “Hello World” using Red’s GUI system.

Red comes with an interpreter, so you can go ahead and run the code below by typing red hello_world_gui.red

Red []
view [ text "Hello World" ]

Red will interpret this code and run it without compiling it to a binary. If you want to produce a binary, amend the code to the following:

Red [ needs: 'View ]
view [ text "Hello World" ]

and run:

red -r -c hello_world_gui.red

The result of this compilation is a single binary that shows the words “Hello World” in a GUI. GUI support is not currently available on Linux yet (it’s experimental), but compiling this works on Windows and Mac. Red supports cross compilation so that you can compile binaries for a different platform, We can get a list of the available cross compilation targets that Red can compile to.

hako ~ red -h
...
Cross-compilation targets:

    MSDOS        : Windows, x86, console (+ GUI) applications
    Windows      : Windows, x86, GUI applications
    WindowsXP    : Windows, x86, GUI applications, no touch API
    Linux        : GNU/Linux, x86
    Linux-ARM    : GNU/Linux, ARMv5, armel (soft-float)
    RPi          : GNU/Linux, ARMv5, armhf (hard-float)
    Darwin       : macOS Intel, console or GUI applications
    macOS        : macOS Intel, GUI-only, applications bundles
    Syllable     : Syllable OS, x86
    FreeBSD      : FreeBSD, x86
    Android      : Android, ARMv5
    Android-x86  : Android, x86

A “Hello World” isn’t that useful though, let’s go further with a simple image viewer where we get a random image, here is the code:

Red [
	title: "Simple Image Viewer"
	author: "Wesley Hill"
	version: 0.1
	needs: 'View
]

rand_img: https://source.unsplash.com/random/310x200
message: "Press Random for a random image!"

view/options [title "Simple Image Viewer"
	 below center
	 pictures: image 310x200 message
	 across
	 random_btn: button "Random" [
		new_image: load rand_img
		pictures/image: new_image
		pictures/text: ""
	]
	 text "A Simple Image Viewer in Red"
][]

The two variables rand_img and message are created above, and we use the view function to invoke Red’s VID dialect and View Engine, we set our title and layout to being in the center of the window. Our images will be of size 310x200 using the pair datatype and we set our button random_btn and text to be across from one another. Finally, once we click the “Random” button, we use the load function to retrieve data from a source. The source needs to be a path, which can be a file, string, binary or url datatype.

In this case we are using the url datatype from rand_img and we set our image with pictures/image: to our new image held in new_image. We only want our image to be displayed, so we set the text in the image to be empty.

We can inspect the datatype with the type? built-in function. Note that Red has over 50+ types.

>> print type? rand_img
url
>> print type? message
string
>> 

Once we run the code above we get our simple image viewer!

…and it also works on Windows

Red can be used for more advanced applications, here are a few:

Automated Photo Copier

For a more advanced application using Red, I wrote a program for my Dad to deal with moving hundreds of photos. Below is the GUI of the program in action, I’m using a collection of random photos to demonstrate the program.

These demo photos are tiny (~5KB on average), and the photos my Dad works with are usually around ~14MB per photo in a sea of thousands of photos.

Parsing the data

The input data is actually an email containing a list of photos that the client has selected.

Selected the following images:

BIRTHDAY PARTY > ABC 7453
TIF_FILE_ID: 0123456789

BIRTHDAY PARTY > ABC 7454
TIF_FILE_ID: 0123456790

...

BIRTHDAY PARTY > ABC 8217
TIF_FILE_ID: 0123456899

The filename of the selected photos takes the form of ABC_1234.jpg. So it would make sense to use Regular Expressions for this problem. Instead, Red has it’s own pattern matching parser originally invented by Rebol called PARSE.

The following regular expression below…

[A-Z]{3,}\s\d\S{3,}

…is similar to the following PARSE rule:

[some letter space 4 digit opt letter]

Given the following rules of letter and digit:

letter: charset [#"A" - #"Z"]
digit:  charset "0123456789"

The reason why opt letter is included in the parse rule, is to catch the ABC 1234A optional edgecase which sometimes appears in the email. Below is how the parser sees this rule:

Using the Red interpreter, we can test that the parse rule is working. For successful matches PARSE returns true and false otherwise.

>> parse "ABC 1234" [some letter space 4 digit]
== true
>> parse "ABC 1234A" [some letter space 4 digit opt letter]
== true
>> parse "ABC 1234AB" [some letter space 4 digit opt letter]
== false

PARSE is a Rebol/Red specific alternative to the now universal regular expression syntax which most if not all experienced programmers are familiar with. It took me a while to learn the syntax and I appreciate the fact that the rules are in plain readable english unlike regex.

Writing this app took me a weekend after prototyping and testing it in Python, it is < 220 lines of code. My Dad uses a Mac, so generating a binary is as easy as compiling the source in release mode for macOS.

red -r -o "APC" -t macOS apc.red --red-only -v 4

and it’s not even 2MB and it. just. works.™

Lines Clone

To demonstrate Red’s networking and serialisation capabilities, I re-created an app I had on my phone called Lines, which is a simple London tube status app. Unfortunately it’s not available on the App Store anymore, but I still have it on my old iPhone. The image on the right shows what it looks like.

Below is the same app implemented in Red. Clicking on the “Lines” will pop open information about a particular tube line.

Currently Red has no built-in JSON parser. I found a JSON parser floating around that was good enough for this demonstration. Building this app took around 3 days of free time to make and is around 897KB in size.

Closing Thoughts

Apart from the GUI system which could do with a Linux implementation (A GTK3 backend is in the works for Red), be aware that Red currently compiles binaries in 32bit. With the Automated Photo Copier app I had problems when I was copying large photos using Red and often the program just crashed all of a sudden. I switched to using cp to copy the photos (Since I knew that my Dad was only using a Mac) by calling call/console to the cp command. At that point it copies the images flawlessly. This would be a different story had he used Windows instead.

Is Red a good alternative to Electron? If you’re building a small internal tool that needs a quick GUI or need a cross platform GUI with less development headaches, then yes. It isn’t production ready yet, but Red has a lot of huge potential in the future looking at their roadmap. I have to admit the learning curve is slightly moderate if you are not familiar with Rebol (resources and links below). An alternative I have yet to try out is Lazarus (maybe in a future blogpost!), but the speed of developing GUI’s in Red is very promising.

The Lines clone code is open source on GitHub.


If you’re interested in learning more about Red, check out these links:

Helpin’Red — (Recommended)

Rebol Documentation — (Recommended)

The Red Language Notebook — (Recommended)

Rebol Core Users Guide

Red Official Documentation — (Slightly incomplete)

Red guides and community material

Red by Example

  1. I used the tried and tested ones, you know: Python, Ruby, Java, C/++/# and JS, but wanted to try something new. In terms of GUI’s for Go, shiny is experimental, there is therecipe/qt and my personal favorite, andlabs/ui

  2. There exists some performant Electron apps (Visual Studio Code), but this is the exception and not the rule. 


Dissertation

Permalink - Posted on 2017-12-10 00:00

Abstract

Emotion Recognition is a field that computers are getting very good at identifying; whether it’s through images, video or audio. Emotion Recognition has shown promising improvements when combined with classifiers and Deep Neural Networks showing a validation rate as high as 59% and a recognition rate of 56%.

The focus of this dissertation will be on facial based emotion recognition. This consists of detecting facial expressions in images and videos. While the majority of research uses human faces in an attempt to recognise basic emotions, there has been little research on whether the same deep learning techniques can be applied to faces in cartoons.

The system implemented in this paper, aims to classify at most three emotions (happiness, anger and surprise) of the 6 basic emotions proposed by psychologists Ekman and Friesen, with an accuracy of 80% for the 3 emotions. Showing promise of applications of deep learning and cartoons. This project is an attempt to examine if emotions in cartoons can be detected in the same way that human faces can.

As a first post, here is my dissertation I did at Lincoln, ‘Deep Learning for Emotion Recognition in Cartoons’. Most of the information is all on the README page on GitHub.

I really enjoyed doing this project and I hope you enjoy reading it too.

PDF HTML


What to expect

Permalink - Posted on 2017-10-19 23:00

Welcome to my new blog, if you’re coming from my other one you may find something very different about it.

Instead of the traditional => "Hello World" most first posts always do, I’ll get straight to the point.

This is my personal blog, where i’ll post about whatever I find very interesting and worth a post.


Expect some posts to cover technology, software engineering, computer science, startups, security, open source, (and my favorite) animation1. But that’s not all.

If time permits, I plan on posting experimental content. Some of these are derived from my software and animations such as sketches, sample code, GIFs! (or JIFs???) and especially zines!2.

This will benefit readers those who like to look at graphics, instead of walls of text. I’m sure I’ll enjoy creating graphics for this blog as I did on my other one.

Here are some of my “greatest hits” from my previous blog.

Bypassing “Snaptcha”

Creating exclusive wifi hotspots with emoji

Setting up Let’s Encrypt on Dokku

Peach App Token Reuse Flaw


Misc

Some other things you should know about this site:

  • Accessibility and Readability comes first.
  • This site mintains a zero dead link policy3.
  • Translations to other languages are welcome, please contact me about this.
  • RSS and JSON feeds are available.
  • Dark mode is available for night owls.
  • …and finally, JavaScript is not required to view this site (except dark mode, sorry).
  1. There will be some random miscellaneous posts too, but don’t expect too much of those… ;) 

  2. I recommend reading Julia Evans’s post on this. 

  3. Unless otherwise stated, If the original link is dead and no other replacement exists, archive.org will be used as a fallback.