Skip to content

Instantly share code, notes, and snippets.

@morgaine
morgaine / bitfields.c
Last active July 16, 2021 22:22
Simple gist to illustrate how C bitfields work
/*
* Simple gist to illustrate how C bitfields work.
*/
#include <stdio.h>
struct {
unsigned char bit0 : 1;
unsigned char bit1 : 1;
unsigned char bit2 : 1;
unsigned char bit3 : 1;
@morgaine
morgaine / hyper_exponential.nickle
Created September 14, 2019 15:14
Hyper-Exponential function in Nickle
#! /bin/env nickle
#
# NAME
# hyper_exponential.nickle
#
# DESCRIPTION
# Calculates the sequence:
# 1
# 2^2
# (3^3)^3
@morgaine
morgaine / fact.erl
Created February 26, 2017 13:01
Erlang: commandline interface to factorial using escript
#! /bin/env escript
%% Simplest use of Erlang's escript and commandline arguments
%% for an interface to the tail-recursive factorial function.
-module(fact).
fact(N) ->
fact(N, 1).
@morgaine
morgaine / shabits.erl
Created February 25, 2017 21:22
Erlang shapes/bits Wk 1 lesson 1.24 assignment, "FP in Erlang"
#! /bin/env escript
% NAME
% shabits.erl -- "FP in Erlang" course, lesson 01.24 assignment
%
% SYNOPSIS
% shabits {triangle-side-A} {triangle-side-B} {triangle-side-C}
%
% INSTALL
% ln -s shabits.erl shabits
@morgaine
morgaine / fib_multi.erl
Last active September 17, 2019 18:28
Fibonacci in Erlang, multiple algorithms, commandline interface
#! /bin/env escript
% NAME
% fib_multi.erl -- Multiple algorithms for Fibonacci numbers
%
% SYNOPSIS
% fib_multi {from-integer} [{to-integer}]
%
% INSTALL
% ln -s fib_multi.erl fib_multi
@morgaine
morgaine / fib.erl
Created February 23, 2017 14:13
Fibonacci in Erlang, commandline interface
#! /bin/env escript
% NAME
% fib.erl -- Erlang exercise with Fibonacci numbers
%
% SYNOPSIS
% fib {from-integer} [{to-integer}]
%
% INSTALL
% ln -s fib.erl fib
@morgaine
morgaine / hyper_exponential.hs
Created October 16, 2016 22:09
Hyper-Exponential function in Haskell
#! /usr/bin/runhaskell
--
-- NAME
-- hyper_exponential.hs
--
-- DESCRIPTION
-- Calculates terms of the HyperExponential sequence:
-- 1
-- 2^2
-- (3^3)^3
@morgaine
morgaine / expr_ok.hs
Last active October 11, 2016 17:41
Brief example of expression parser in Haskell with Parsec
#! /usr/bin/runhaskell
--
-- FutureLearn Haskell Course Sep-Oct 2016
-- Lessons 4.6: Parsing Text Using Higher-Order Functions
-- Section: Expression parsers
--
module Main where
import Text.Printf
@morgaine
morgaine / monitor_hosts_loop.sh
Created December 1, 2012 14:17
Example snippet showing use of shell to display ping status on LEDs
#! /bin/sh
LED_CONTROL_CMD="switch_led"
LED_CONTROL_CMD="echo"
BASE_LED_NUMBER="5"
INTERVAL="30"
HOSTS="
google.com
slashdot.org