Skip to content

Instantly share code, notes, and snippets.

@erichschroeter
erichschroeter / timestamp.c
Created October 17, 2014 18:20
timestamp
#include <stdio.h>
#include <time.h>
void ptimestamp_micro(struct timespec *now, char *text)
{
long us = (now->tv_sec * 1000000) + (now->tv_nsec / 1000);
printf("%ld%s", us, text);
}
@erichschroeter
erichschroeter / generate.c
Last active August 29, 2015 14:05
Generate program for version header.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include <time.h>
#define VERSION_H \
"#ifndef %s_VERSION_H\n" \
"#define %s_VERSION_H\n" \
@erichschroeter
erichschroeter / req.sh
Created June 13, 2014 02:19
Requirement management based on Git.
#!/bin/sh
usage() {
cat << EOF
usage: req [--version] [--help] <command> [<args>]
The most commonly used req commands are:
add Add requirement contents to the index
new Create a requirement
init Create an empty req repository
@erichschroeter
erichschroeter / HelloLibrary.cs
Last active August 21, 2021 10:33
A helloworld example of marshalling an array to C# created in C.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace HelloApp
{
class HelloLibrary
{
@erichschroeter
erichschroeter / HelloLibrary.cs
Created April 25, 2014 15:02
Simple marshalling hello world with nested struct.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace HelloApp
{
class HelloLibrary
{
@erichschroeter
erichschroeter / Makefile
Last active March 8, 2023 06:46
etherwake
.PHONY: clean uninstall
prefix ?= /usr
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
ETHERWAKE_src = ether-wake.c
ETHERWAKE_bin = ether-wake
ETHERWAKE_tgt = $(DESTDIR)$(bindir)/etherwake
@erichschroeter
erichschroeter / timer_unix.c
Last active November 9, 2018 10:11
Cross-platform timer example in C.
#include <stdio.h>
#include <time.h>
#define PRINT_INTERVAL 1000 /* in milliseconds */
#define MILLI 0
#define MICRO 1
#define NANO 2
#define RESOLUTION MILLI
long diff_nano(struct timespec *start, struct timespec *end)
@erichschroeter
erichschroeter / batt.py
Created November 15, 2013 19:36
Print the battery percentage using colors for High, Medium, Low battery levels. Uses acpitool to parse for battery percentage level.
#!/usr/bin/env python
# coding=UTF-8
import sys, subprocess
p = subprocess.Popen(["acpitool", "-ab"], stdout=subprocess.PIPE)
output = p.communicate()[0]
# find the line with the battery percentage
o_cur = [l for l in output.splitlines() if '%' in l][0]
@erichschroeter
erichschroeter / termios_dbg.c
Created June 7, 2013 14:20
Debug statements for termios struct.
#include <stdio.h>
#include <sys/ioctl.h>
#include "termios_dbg.h"
#define CHECK_BIT(var, pos) ((var) & (1<<(pos)))
void ptermios_iflag(struct termios *tty)
{
printf("c_iflag=0x%x\n", tty->c_iflag);
@erichschroeter
erichschroeter / queue.sh
Created November 28, 2012 13:25
Shell script implementation of a Queue.
#!/bin/bash
#
# This script encapsulates the functionality of a queue. It requires there to be
# an input file with the data in the queue being separated on different lines.
#
INPUT=queue.txt
OUTPUT=trash.txt
CMD=/usr/bin/vlc