Showing posts with label Off-Topic. Show all posts
Showing posts with label Off-Topic. Show all posts

2021-04-23

Exponential Moving Average Calculations in SQL Server

Financial systems use a large variety of different analysis functions to identify trends and provide other derivations from periodic price or volume data.  One of these is the Exponential Moving Average (EMA), which provides a price average where more recent periods are weighted more significantly than older periods.  I'm going to demonstrate a way this can be calculated in SQL Server's T-SQL in a set-based way.

The EMA has only one parameter, which is a number of periods from which the weighting value is calculated.

The calculation is:

weight = 2 / ( number of periods + 1 )  [which will yield a value between 0 and 1]

EMA = CurrentPrice * weight + PreviousPeriodEMA * (1 - weight)

    = p0 * w + EMA1 * (1 - w)

where p0 is the price for the current period, EMA1 is the EMA value for the previous period, and w is the weighting factor.

As each EMA is calculated from the previous EMA, most solutions calculate this iteratively, but it can be calculated in a set-based manner.

2021-04-22

Row Generation in SQL Server

While writing complex queries for SQL Server, I have often needed to generate a specific number of records in order to solve a problem in a set-based manner.  At times like this I reach for a trusty Row Generator functions (also referred to as a "numbers table").

Here is a simple implementation of a row generator as a table-valued function:

2021-04-12

Certificate Deep Dive - Part 1 - What's a Certificate?

[Nothing to do with the Operating System at the moment I'm afraid, but this is an article I have wanted to write for a while.]

A few years ago, if you had asked me what technical subjects felt I should know more about, I would have said Time ZonesCharacter Encoding, and most definitely Certificates, which we'll look at today.

Despite their widespread use and amazing utility, the lack of good information and the obscurity of the tools for working with them lead many software developers to never grasp the benefits of them.  Over the next few posts, we'll do a deep dive into Certificates and attempt to cover off as much information as possible to give a good grounding and reference of what certificates are, why you might want to use them, and much more besides.

So buckle up, everybody, this is going to be a long few articles just because there is a lot to cover.  This first one is broken down into a "Question & Answer" form where the questions should logically follow each other and each adds progressively more detail.  I have tried to ensure that everything in here is correct and isn't misleading, but I can't be held liable for anything you do with this and you're encouraged to do your own research as well.

[Speaking of character encoding, if you want to weep for the species about how little software developers understand the topic, this StackOverflow Question is a disturbing read.]

2014-09-16

What the world needs is more Doom

Looks like I'm not the only one toying with getting Doom running on the metal.  This is a post from a security researcher called Michael Jordon who found that some Canon Pixma printers have a vulnerability that means they can have custom firmware uploaded to them, and that the ARM processor and LCD display on the printer is just about capable of running Doom ...

http://www.contextis.co.uk/resources/blog/hacking-canon-pixma-printers-doomed-encryption/

(For the record, my first thought was a 0x10 key, don't know where he saw a 0x30 key in that data  :p  )

2013-12-01

The Biggest Letters in the Whole Wide World

So, I was watching TV with my daughter the other day and a character in one of the kids programs said they were trying to make "the biggest '9' in the whole wide world".  This got me to thinking, where is the biggest '9' in the world?  For that matter, what about all the other letters?

I'd say the only ground rules are that the letter has to be a physical structure, and that the structure was intended to represent that letter (so an American Football goalpost doesn't count as a 'Y').  For the moment, I'll restrict this to the Latin alphabet

I guess most of them are going to be found on buildings or perhaps ships.  The "HOLLYWOOD" sign might scoop six of the letters, but where are the others?  Some of them may actually be quite small.  Suggestions in the comments ...


  • A
    • "READYMIX[5] 240 metres tall.
    • "BISMARK[10] 87 metres tall (estimated).
    • "CASAS BAHIA 1[7] 71 metres tall (estimated).
    • "Coca Cola[3] 15.5 metres tall (estimated).
    • "PADDY POWER[1] 15.2 metres tall.
  • B
    • "BISMARK" [10] 87 metres tall (estimated).
    • "CASAS BAHIA 1" [7] 71 metres tall (estimated).
  • C
    • "LUECKE[4] 950 metres tall (estimated).
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "Coca Cola" [3] 32 metres tall (estimated)
  • D
    • "READYMIX[5] 240 metres tall.
    • "GOD'S WISDOM[9] 28 metres tall (estimated).
    • "PADDY POWER[1] 15.2 metres tall.
    • "HOLLYWOOD[2] 14 metres tall.
  • E
    • "LUECKE[4] 950 metres tall (estimated).
    • "READYMIX[5] 240 metres tall.
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "PADDY POWER[1] 15.2 metres tall.
  • F
    • "FOWL[11] 55 metres tall (estimated).
  • G
    • "GOD'S WISDOM[9] 28 metres tall (estimated).
  • H
    • "CASAS BAHIA 1[7] 71 metres tall (estimated).
    • "HOLLYWOOD[2] 14 metres tall.
    • Pink suggested a Helipad somewhere?
  • I
    • "READYMIX[5] 240 metres tall.
    • "BISMARK[10] 87 metres tall (estimated).
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "CASAS BAHIA 1[7] 71 metres tall (estimated).
  • J
    • "JOSTWINE.COM" [6] 75 metres (estimated).
  • K
    • "LUECKE[4] 950 metres tall (estimated).
    • "BISMARK[10] 87 metres tall (estimated).
    • "FOWL[11] 55 metres tall (estimated).
  • L
    • "LUECKE[4] 950 metres tall (estimated).
    • "Coca Cola[3] 32 metres tall (estimated).
    • "HOLLYWOOD[2] - 14 metres tall.
  • M
    • "READYMIX[5] 240 metres tall.
    • "BISMARK[10] 87 metres tall (estimated).
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "Platte Mound M" - 73 metres tall.
  • N
    • "JOSTWINE.COM[6] 75 metres (estimated).
  • O
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "FOWL[11] 55 metres tall (estimated).
    • "GOD'S WISDOM[9] 28 metres tall (estimated).
    • "Coca Cola[3] 15.5 metres tall (estimated).
    • "PADDY POWER[1] 15.2 metres tall.
    • "HOLLYWOOD[2] 14 metres tall.
  • P
    • "PADDY POWER" [1] 15.2 metres tall.
    • "PLAZA MAYOR[8] 14 metres tall (estimated).
    • "P&O" Cruise Ships 8 metres tall (estimated)
  • Q
  • R
    • "READYMIX[5] 240 metres tall.
    • "BISMARK[10] 87 metres tall (estimated).
    • "PADDY POWER[1] 15.2 metres tall.
    • "PLAZA MAYOR[8] 14 metres tall (estimated).
  • S
    • "BISMARK[10] 87 metres tall (estimated).
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "GOD'S WISDOM[9] 28 metres tall (estimated).
  • T
    • "JOSTWINE.COM[6] 75 metres (estimated).
  • U
    • "LUECKE[4] 950 metres tall (estimated).
    • "Block U" 30 metres tall.
  • V
  • W
    • "JOSTWINE.COM[6] 75 metres (estimated).
    • "FOWL[11] 55 metres tall (estimated).
    • "GOD'S WISDOM[9] 28 metres tall (estimated).
    • "PADDY POWER[1] 15.2 metres tall.
    • "HOLLYWOOD[2] 14 metres tall.
  • X
    • "READYMIX" [5] 240 metres tall.
  • Y
    • "READYMIX[5] 240 metres tall.
    • "PADDY POWER[1] 15.2 metres tall.
    • "HOLLYWOOD[2] 14 metres tall.
    • "PLAZA MAYOR[8] 14 metres tall (estimated).
  • Z
    • "PLAZA MAYOR[8] 14 metres tall (estimated).
  • 0
  • 1
    • "CASAS BAHIA 1[7] 71 metres tall (estimated).
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9



  • [1]  "PADDY POWER" http://www.telegraph.co.uk/advertising/news/7465528/Worlds-biggest-advertising-sign-built-overlooking-Cheltenham-Racecourse.html

    [2]  "HOLLYWOOD" https://maps.google.com/maps?ll=34.134029,-118.321611&spn=0.001039,0.002064&sll=34.092809,-118.328661&sspn=0.06653,0.132093&t=h&z=20

    [3]  "Coca Cola" https://maps.google.co.uk/maps?ll=-18.529371,-70.249503&spn=0.00238,0.004128&sll=-18.481898,-70.250197&sspn=0.019049,0.033023&t=h&z=19

    [4]  "LUECKE" https://maps.google.co.uk/maps?ll=30.081684,-97.140995&spn=0.00869,0.016512&sll=52.8382,-2.327815&sspn=12.439947,33.815918&t=h&z=20

    [5]  "READYMIX" https://maps.google.co.uk/maps?ll=-32.21714,125.361149&spn=0.016992,0.033023&sll=52.8382,-2.327815&sspn=12.439947,33.815918&t=h&z=16

    [6]  "JOSTWINE.COM" https://maps.google.co.uk/maps?ll=45.800234,-63.381817&spn=0.003501,0.008256&sll=52.8382,-2.327815&sspn=12.439947,33.815918&t=h&z=18

    [7]  "CASAS BAHIA 1" https://maps.google.com/maps?ll=-23.23482,-46.862687&spn=0.004614,0.008256&t=h&z=18

    [8]  "PLAZA MAYOR" https://maps.google.com/maps?ll=36.655336,-4.47956&spn=0.001007,0.002064&sll=36.655314,-4.479591&sspn=0.001007,0.002064&t=h&z=20

    [9]  "GOD'S WISDOM" https://maps.google.com/maps?ll=42.46578,-72.08783&spn=0.001852,0.004128&sll=42.465956,-72.089957&sspn=0.014816,0.033023&t=h&z=19

    [10]  "BISMARK" https://maps.google.com/maps?ll=46.815614,-100.722774&spn=0.001718,0.004128&sll=46.81627,-100.720757&sspn=0.003436,0.008256&t=h&z=19

    [11]  "FOWL" https://maps.google.com/maps?ll=44.829679,-87.905474&spn=0.00178,0.004128&t=h&z=19