Skip to content

Instantly share code, notes, and snippets.

View formix's full-sized avatar

Jean-Philippe Gravel formix

  • Formix Consulting
  • Saint-Honoré-De-Chicoutimi, Saguenay, Quebec, Canada
  • LinkedIn in/jpgravel
View GitHub Profile
@formix
formix / nested_streams_close_experiment.py
Last active October 12, 2023 16:09
Experiment with python3 nested file streams to test if closing the tip stream will actually close the internal and the root streams.
"""
Experiment with python3 nested file streams to test if closing the tip stream will actually close
the internal and the root streams.
"""
import io
import gzip
FILE_PATH = "experiments/data/nested_stream_close_experiment.txt.gz"
@formix
formix / cb.js
Last active February 10, 2023 13:22
Javascript circuit breaker function wrapper
/**
* Circuit breaker function wrapper.
*
* @param {*} afn An async function.
* @param {*} retries Number of retries before tripping the breaker.
* @param {*} delay Time in ms to wait before calling 'afn' again.
* @returns An async function wrapper around 'afn'.
*/
function cb(afn, retries = 3, delay = 1000) {
let tripped = false;
@formix
formix / combine.js
Last active August 30, 2022 09:37
Javascript combinatorial table example
function combine(combins, tables, getSortKey = (v => v.key)) {
let validCombins = [];
for (let i =0; i < combins.length; i++) {
let c = combins[i];
let valid = true
for (const k in c) {
if (tables[k].selection === undefined) continue;
let sel = tables[k].selection;
valid &= sel === c[k];
@formix
formix / traffic-light-challenge.ino
Last active March 4, 2021 15:09
This is a traffic light finite state machine demonstration / challenge. Debug it and do the challenges at the end of the code.
// Copyright 2020 Jean-Philippe Gravel <[email protected]>
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
#create /etc/systemd/system/[myapp].service
[Unit]
Description=[myapp]
After=network.target
[Service]
ExecStart=/usr/local/bin/node /home/pi/proj/app.js
Restart=always
RestartSec=10
@formix
formix / propvm.snippet
Created November 26, 2018 17:03
ViewModel property snippet for visual studio 2017
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>View Model Property</Title>
<Description>
Declares a property and member suitable for Viewmodel implementation.
@formix
formix / ViewModelBase.cs
Last active March 5, 2019 22:26
Base class vor a MVVM ViewModel
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Template.Project.ViewModels
{
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
@formix
formix / queryString.js
Last active November 9, 2018 15:34
Convert an URL query string parameter list to a Javascript object.
//***************************************************************************
// Copyright 2018 Jean-Philippe Gravel, P.Eng., PSEM
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
@formix
formix / FixedLinkedList.cs
Last active August 15, 2018 00:20
The freaking .NET LinkedList<T> is broken since its inception (2.0). This implementation finally makes it an IList<T>.
using System;
using System.Collections.Generic;
namespace Formix.Fixes.Collections.Generic
{
public class FixedLinkedList<T> : LinkedList<T>, IList<T>
{
public T this[int index]
{
get
@formix
formix / .vimrc
Last active May 17, 2018 17:36 — forked from JeffreyWay/.vimrc
My .vimrc file
set nocompatible " Disable vi-compatibility
set t_Co=256
colorscheme xoria256
set guifont=menlo\ for\ powerline:h16
set guioptions-=T " Removes top toolbar
set guioptions-=r " Removes right hand scroll bar
set go-=L " Removes left hand scroll bar
set linespace=15