Skip to content

Instantly share code, notes, and snippets.

View Linux-cpp-lisp's full-sized avatar

Alby M. Linux-cpp-lisp

View GitHub Profile
@Linux-cpp-lisp
Linux-cpp-lisp / cpp-posix-errors.cpp
Created May 24, 2012 13:20
A few small macros used to simplify error handling in C++ code that uses POSIX and UNIX system calls. Depends on an exception class UNIXError, which just happens to have an argument-less constructor that will get an error string based on the current value
#define ERR(__statment, __retVar) ((__retVar=(__statment))==-1 ? throw UNIXError() : (__retVar))
#define ERR_ERRVAL(__statment, __retVar, __errval) (((__retVar)=(__statment))==(__errval) ? throw UNIXError() : (__retVar))
@Linux-cpp-lisp
Linux-cpp-lisp / UNIXError.cpp
Created May 24, 2012 13:23
A set of classes used to simplify error handling with POSIX and UNIX functions in C++ programs. Header and `.cpp` files. Contains a class that works with `errno` errors, and one that works with `getaddrinfo` errors.
/*
* File: UNIXError.cpp
* Author: a
*
* Created on March 19, 2012, 5:59 PM
*/
#include "UNIXError.h"
#include <netdb.h>
@Linux-cpp-lisp
Linux-cpp-lisp / gist:2890984
Created June 7, 2012 19:20
Basic Sandboxing
require("timeout")
t=Thread.new(codeStr) do |code|
$SAFE=4
Timeout::timeout(5) {eval code} rescue nil
end
@Linux-cpp-lisp
Linux-cpp-lisp / gist:3011405
Created June 28, 2012 13:30
How to make Ruby class methods private
class Foo
class << self
private
def private_class_method; end
protected
def protected_class_method; end
end
end
@Linux-cpp-lisp
Linux-cpp-lisp / main.c
Created July 21, 2012 15:13
Basic C Hello world with stdio.
#include <stdio>
int main(int argv, char**argc) {
printf("Hello, world");
}
@Linux-cpp-lisp
Linux-cpp-lisp / gist:3861582
Created October 9, 2012 21:28
Some Basic HTML, CSS, and JavaScript
HTML:
<button id="b1" onclick="click()">Hi!</button>
JS:
function click() {
alert("Hi!");
}
@Linux-cpp-lisp
Linux-cpp-lisp / num_range_shrink.c
Created January 6, 2014 19:39
A little function to take a value in the range 0-x and convert them to values in a different, smaller range.
unsigned int num_range_shrink(unsigned int orig, unsigned int old_limit, unsigned int new_upper) {
float interval = old_limit / new_upper;
for(int i = 1; i <= new_upper; i++) {
if(orig < i*interval) {
return i-1;
}
}
return 0;
}
@Linux-cpp-lisp
Linux-cpp-lisp / boxes.py
Last active October 12, 2017 16:36
A memory-optimized algorithm for computing N(epsilon) when finding the capacity dimension of a dataset
#boxes.py: Compute N(epsilon) for the "box-counting" or capacity dimension of a data set.
# Alby Musaelian, 12/2016.
import numpy as np
import warnings
def memory_optimized_n_eps(traj,
eps,
memory_slot_limit=100*1024*1024,
@Linux-cpp-lisp
Linux-cpp-lisp / midi_translation_table.lua
Last active February 14, 2019 05:38
MIDI Node Mapping Plugin -- Ardour Lua DSP Script
ardour {
["type"] = "dsp",
name = "MIDI Remap Notes",
category = "Utility", -- "Utility"
license = "MIT",
author = "Alby Musaelian",
description = [[Map arbitrary MIDI notes to others. Affects Note On/Off and polyphonic key pressure.]]
}
N_REMAPINGS = 10
@Linux-cpp-lisp
Linux-cpp-lisp / spiral.md
Last active May 29, 2019 20:58
Flexible, configurable generation of natural numbers in a spiral

 Generate and print a spiral of natural numbers up to N with fully configurable shape and spacing.

Examples:

$ python3 spiral.py 50 square 2 
                                     
                                     
     32 31 30 29 28 27 26 25         
     33                   24