Skip to content

Instantly share code, notes, and snippets.

View FergusInLondon's full-sized avatar
😑

Fergus FergusInLondon

😑
View GitHub Profile
@FergusInLondon
FergusInLondon / rolling_average.js
Last active October 3, 2018 14:28
A little JS object for calculating rolling averages, complete with callbacks upon update.
/* Fergus In London - https://fergus.london - <fergus@fergus.london>
*
* Simple little function for calculating rolling averages, both simple and
* weighted. Example can be found on the GitHub Gist, or on my website.
*
* Do as you please, no rights reserved and no warranties provided. :)
*/
@FergusInLondon
FergusInLondon / collection.c
Created May 2, 2017 19:26
Dynamic array/container implementation in C - includes iterator. (WIP / Brain-Dump)
#include <string.h> // memcpy
#include <stdlib.h> //
/**
*
*
*/
typedef struct {
uint8_t object_count, iteration_counter, max_count;
uint8_t *indices_in_use;
@FergusInLondon
FergusInLondon / problems.py
Created May 1, 2017 17:18
Use dbus to parse system problems
# Fergus In London - https://fergus.london <fergus@fergus.london>
#
# Uses the org.freedesktop.problems dbus channel to read out reported problems.
#
# Requires pydbus from pip.
# Requires python-gobject and glib installed on your distro.
#
import sys
import argparse
from pydbus import SystemBus
@FergusInLondon
FergusInLondon / events.h
Last active April 27, 2017 20:13
Really simple events/listeners registry in C
/**
* Simple little event registry built around the worlds most simplistic
* linked list implementation. Allows you to register a function (void())
* against a integer value, and provides a mechanism for triggering the
* associated functions for an integer.
*
* Not a great deal of use beyond those fun little weekend Arduino type
* projects.
*
* @see example.c
@FergusInLondon
FergusInLondon / roller.js
Last active April 27, 2017 17:04
Simple Rolling Average function
/* Fergus In London - https://fergus.london - <fergus@fergus.london>
*
* Simple little function for calculating rolling averages, both simple and
* weighted. Example can be found on the GitHub Gist, or on my website.
*
* Do as you please, no rights reserved and no warranties provided. :)
*/
/**
@FergusInLondon
FergusInLondon / base64_encode.c
Last active April 17, 2017 01:01
Base 64 Encoding in C
#include <stdio.h>
#include <stdlib.h>
#define FIRST_SIX_INDEX (buf[0] & 0xfc) >> 2
#define SECOND_SIX_INDEX ((buf[0] & 0x03) << 4) + ((buf[1] & 0xf0) >> 4)
#define THIRD_SIX_INDEX ((buf[1] & 0x0f) << 2) + ((buf[2] & 0xc0) >> 6)
#define FOURTH_SIX_INDEX buf[2] & 0x3f
char base64_map[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
@FergusInLondon
FergusInLondon / shuffler.js
Last active April 14, 2017 22:47
Simple array shuffler example.
/**
* shuffle(array[]) - Shuffles an array via a simplistic
* algo, not too dissimilar to Fisher-Yates.
*
* Ignore the -ahem- "clever" variable swapping one-liner,
* that's all it does.
*
* @param array
* @return array
*/
### Keybase proof
I hereby claim:
* I am fergusinlondon on github.
* I am fergusinlondon (https://keybase.io/fergusinlondon) on keybase.
* I have a public key ASAZUkUuHB0BhpbpaL2yBsfar2Rj2ATeaS2RfjJMaiFkpQo
To claim this, I am signing this object: