Using __builtin_offset for data encapsulation in C

I ran into __builtin_offset in the VLC codebase where they used it to implement a macro called ‘container_of’ (which according to some research I did online, originated from the linux kernal codebase). I found it used in this way 1) Malloc the entirety of what’s needed for a widget 2) Put the public facing data…

Converting between kCVPixelFormatType_420YpCbCr8BiPlanarFullRange and kCVPixelFormatType_420YpCbCr8PlanarFullRange

I wish this was already on the internet when I was writing it, so I am posting this here! Sometimes you have buffers coming from different sources and you need them in the same pixel format. For example if one is coming from AVCaptureSession’s CMSampleBuffers and another is coming from some other video stream. There…

Monaco editor’s provideCompletionItems callback not firing (TriggerCharacters not working)

I ran into a bug where the monaco editor was not showing the autocomplete dropdown even though I had specified my trigger characters correctly. The root cause was because of 2 issues: I did not register my custom language using monaco.languages.register(….). Once I did register my language, I was registering it after the editor was…

Little-Known Awesome Algorithms: Fenwick Trees

Contrived Use Case Imagine that we are creating an analytics tool for a financials brokerage, where orders are coming in all the time. Let’s say we’re interested in knowing how many orders fall between a certain value (a range query), in real-time. Lets say that orders can fall between $0.01 and $5M, and we want to let our…

How to program a Gaussian Blur without using 3rd party libraries

  What is a Gaussian Blur? Something I found fairly difficult to find online was a simple explanation on how to implement my own Gaussian Blur function. This article will explain how to implement one. The basic idea behind a Gaussian Blur is that each pixel becomes the average of the pixels around it, sort of. Instead…

Over-the-wire Natas28 Security Puzzle

You are given a search tool which finds jokes which contain your search term. The form submission returns a 302 redirect to another page with an encrypted get param already attached. This encrypted param must contain your input in some way. They look something like this: G%2BglEae6W%2F1XjA7vRm21nNyEco%2Fc%2BJ2TdR0Qp8dcjPIWwm0xpPpp9XnS4%2FRG86COn7KRweZpSA6OMfSSZI8b4nOKX%2FtKRQAkZ3UXWuWWu9bzTfM5xp7c4R9mULvO1icC The data is url encoded and base 64…

Android: getCallingPackage returns null and an alternative

If you ever want to verify the package name of an application which is deeplinking into you, you might take a look at Activity’s ‘getCallingPackage’. The gotcha here is that this will always be null unless the activity was started with startActivityForResult. Unfortunately, setActivityForResult may not work for your app (especially if it requires changing…

Option Delta vs Actual % In-The-Money

Been playing around with options for the last few months and recently I purchased my first batch of historical CBOE options data. This is my first piece of research with the data-set. Delta is frequently used as an approximation for the probability of an option expiring in the money (This is different from probability of…