Skip to content

Instantly share code, notes, and snippets.

View christophevg's full-sized avatar
🤓
nerding

Christophe VG christophevg

🤓
nerding
View GitHub Profile
@christophevg
christophevg / gist:789689
Created January 21, 2011 13:43
A QnD Solution to GeertVL's Homework ;-)
// Part 1.
// Implement a function prototype extension that caches function results for
// the same input arguments of a function with one parameter.
//
// For example:
// Make sin(1) have the result of Math.sin(1), but use a cached value
// for future calls.
Function.prototype.withCaching = function withCaching() {
if( ! this.cache ) { this.cache = {}; } // lazy initialization of cache
@christophevg
christophevg / gist:61865cf042a68727a552
Created November 26, 2014 11:19
Illustration of Python generators
# Illustration of Python generators
def count_down(size):
print "starting generation"
while size > 1:
print "yielding"
yield size
size -= 1
print "finishing generation"
yield size
@christophevg
christophevg / array_of_consecutive_numbers.c
Created December 9, 2014 11:31
How to create an array of consecutive numbers in C
#include <stdio.h> // for printf
#define START 123 // initial number to use to start sequence
#define MAX 5 // maximum number of items in the list
int main(void) {
// create list on the stack
int lst[MAX];
// fill list
@christophevg
christophevg / README.md
Last active March 16, 2016 13:22
State Machines for Dries

State Machines for Dries

Three implementations:

  • demo_switch.c most basic, switch-based state machine
  • demo_functions.c a little nicer on the eye with functions as state handlers
  • demo_functions_results.c a more generic state machine framework with reconfigurable state transitions

Normal operation

Keybase proof

I hereby claim:

  • I am ChristopheVG on github.
  • I am christophevg (https://keybase.io/christophevg) on keybase.
  • I have a public key whose fingerprint is F5EC FEB6 A1B8 0CB6 CFA7 FDE7 897E 3E40 AABF 2ECC

To claim this, I am signing this object:

@christophevg
christophevg / LinkedTreeViews.md
Last active February 16, 2017 21:35
Connecting nodes of two TreeViews using C#/WinForms

This Gist is a combination a many different solutions found around the net. It shows how to create two TreeViews and visually connect two nodes in each of them.

Most "problems" are covered:

  • Invisible nodes (e.g. when collapsed or scrolled out of sight)
  • Back- and forth notifications of updates between TreeViews and parent Form
  • Two LinkedTreeViews are combined in LinkedTreeViews Panel
  • Drag and Drop support allows to create/remove links
@christophevg
christophevg / hueToRGB.c
Created December 16, 2017 10:24
Function to convert a color to its Red, Green, and Blue components
// Courtesy http://www.instructables.com/id/How-to-Use-an-RGB-LED/?ALLSTEPS
// function to convert a color to its Red, Green, and Blue components.
void hueToRGB(uint8_t hue, uint8_t brightness, bool invert) {
uint16_t scaledHue = (hue * 6);
uint8_t segment = scaledHue / 256; // segment 0 to 5 around the
// color wheel
uint16_t segmentOffset =
scaledHue - (segment * 256); // position within the segment

Keybase proof

I hereby claim:

  • I am christophevg on github.
  • I am christophevg (https://keybase.io/christophevg) on keybase.
  • I have a public key ASAchSq6OMeHwqCkToGzHbZq1CQFLsNJDZxCg0p1hGMFhgo

To claim this, I am signing this object: