Hacking Together HTML With YAML And Mustache

Forewarning, this is a hack and an ugly one too. Without getting into the backstory, the idea was to see if it is possible to render YAML data to HTML using a Mustache template, all locally (i.e. no server, just a single local HTML file). Turns out it is possible... sort of.

Before getting to the code, a few notes:

  • This probably shouldn't be used for anything ever (although it was a fun experiment …
more ...

Thoughts On Script Naming

For a while now, I have had the mindset that any high-level operation related to a software project should be captured as an OS-native script kept either in the repo's root directory or an appropriate subdirectory. For example, the following scripts are located in the root directory of my blog repo:

  • _Build_HTML.bat
  • _Cleanup.bat
  • _Deploy_SSH.bat
  • _Run_Test_Server.bat

A few things worth noting about the filenames alone:

  • The scripts are Windows-native batch files since …
more ...

C Polymorphism

Date Tags c

Polymorphism, when done right, is a powerful method of simplifying software implementation. There are multiple types of polymorphism, here is a simple example of runtime (aka dynamic) polymorphism in C:

#include <stdio.h>
#include <stdlib.h>

typedef struct animal_s {
    void (*speak)(void);
} animal_t;

void speak_like_a_duck(void)
{
    printf("quack!\r\n");
}

void speak_like_a_dog(void)
{
    printf("woof!\r\n");
}

animal_t *create_duck(void)
{
    animal_t *duck = malloc(sizeof(animal_t));
    duck->speak = &speak_like_a_duck;
    return(duck);
}

animal_t *create_dog(void)
{
    animal_t *dog …
more ...

C Moving Average

Date Tags c

Moving averages are useful since they do not require a buffer of samples to be maintained. Here is a simple implementation in C:

#include <stdio.h>

float ave(float num)
{
    static float fAve = 0.0f;
    static unsigned int fSmp = 0;
    float weight = 0.0f;

    fSmp++;
    weight = 1.0f / fSmp;
    fAve = (weight * num) + ((1 - weight) * fAve);

    return(fAve);
}

int main(int argc, const char *argv[])
{
    char str[100] = {0};
    float num = 0;

    /* Run until user enters …
more ...

Python Geometric Mean

Date Tags python

Need to calculate a geometric mean in Python? You could use Numpy or this one-liner:

# NOTE: This import is only needed for Python3.
from functools import reduce

# Geometric mean of list `n`:
geomean = lambda n: reduce(lambda x,y: x*y, n) ** (1.0 / len(n))

print(geomean([1,2,3,4]))
# Result: 2.2133638394
more ...


Python String Index Replace

Date Tags python

Python does not allow string to be modified via indexed assignment. For example, a = "hello"; a[1] = "x" will produce a TypeError: 'str' object does not support item assignment error. Grr!

The following one-liner stridxrep() can be used if the need ever arises:

a = "hello"

# Python doesn't allow the following:
# a[1] = "x"

# A 'string index replace' function.
stridxrep = lambda s, i, r: "".join([(s[x] if x != i else r) for x in …
more ...

Four Technologies for 2014

Date Tags software

Technology moves fast. Really fast. The following are some software technologies that I will be keeping an eye on in 2014:

  1. Docker - Brilliant container manager.
  2. Rust - Promising systems language.
  3. Emscripten - Mind-bending JavaScript compiler.
  4. D3.js - Beautiful data visualization.

While these technologies are not necessarily new, my prior experience with them is limited.

more ...

Hi, I am Jeff Rimko!
A computer engineer and software developer in the greater Pittsburgh, Pennsylvania area.