Skip to content

Instantly share code, notes, and snippets.

View amullins83's full-sized avatar

Austin Mullins amullins83

  • Milsoft Utility Solutions
  • Abilene, TX
View GitHub Profile
@amullins83
amullins83 / Polymorphism in C.md
Last active June 8, 2021 18:51
Polymorphism in C

#Polymorphism in C

##Summary

C is the lengua franca of embedded development. It is incredibly flexible, with built-in language features for imperative, functional, and object-oriented programming. However, getting inheritance to work effectively in standard C requires a little boiler-plate code, of which I've provided an example here.

@amullins83
amullins83 / debounce.go
Last active August 29, 2015 14:04
Generic Debounce in Go
package main
import (
"fmt"
"time"
)
func debounce(interval time.Duration, f func(argList []interface{})) func([]interface{}) {
timer := &time.Timer{}
return func(argList []interface{}) {
@amullins83
amullins83 / delete_matrix_rows.c
Created February 25, 2015 22:13
Using m_vector in a real project
#include <stdio.h>
#include <malloc.h>
#include "m_vector.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TRUE 1
#define FALSE 0
@amullins83
amullins83 / README.md
Created September 15, 2015 19:05
Invoke C++ code within C

#Invoking C++ code within a C file

I don't know how useful this is in practice, but today I learned that you can invoke C++ code within a C library if needed. The basic process is to forward-declare C++ structs, then declare the function(s) to be invoked from the C library within an extern "C" block. The file containing these declarations will need to be included in the C source file and in the C++ header and source files. The C file can then be compiled normally with gcc and the C++ source with g++. Finally, the executable will need to be linked with g++ so that C++ operators and keywords will be defined.

This trivial example seems silly, but one can imagine a scenario where a C-library does useful work while taking a function pointer as an argument. The function declared in the extern "C" block here might be accepted as such an argument, and as long as the final

@amullins83
amullins83 / manifest.json
Last active March 2, 2016 14:51
Simple Page Mangler Chrome Extension
{
"manifest_version": 2,
"name": "My Drumpf",
"version": "0.0.1",
"description": "Replaces occurrences of 'Drumpf' with 'Drumpf'",
"author": "Austin Mullins",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["transform.js"]
}]
@amullins83
amullins83 / transform.js
Created March 2, 2016 14:55
Simple Chrome Mangler Extension transform script
function drumpfinate(text) {
return text.replace(/\bTrump\b/g, "Drumpf");
}
(function transformTree(transform) {
var walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
false
@amullins83
amullins83 / string_size.cpp
Created April 9, 2016 15:49
sizeof(string) does not give you the string's length.
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
string sizeStr = "This is a test string that is rather long. Many bytes. Oh yes, quite a few bytes.";
@amullins83
amullins83 / gen_ostream_stuff.cpp
Created April 12, 2016 16:07
Generic operator<< definition?
#include <iostream>
#include <string>
template <typename T>
std::ostream& streamOutEnum(std::ostream& os, T thing)
{
return os << GetString(thing);
}
enum Type1 {
@amullins83
amullins83 / generic_enum.cpp
Last active April 14, 2016 14:24
Attempt to create a reusable enumerated type wrapper
#include <iostream>
#include <string>
enum Type1 {
What,
Hey
};
enum Type2 {
Yo,
@amullins83
amullins83 / count_digits.cpp
Created June 14, 2016 21:30
Counting Digits
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <stdint.h>
using namespace std;
size_t countDigitsLog(int number)
{