Skip to content

Instantly share code, notes, and snippets.

View JonathonReinhart's full-sized avatar

Jonathon Reinhart JonathonReinhart

View GitHub Profile
// unaligned.h
// Safely access unaligned multi-byte values (e.g on ARM)
// Jonathon Reinhart
// The use of 'packed' forces the compiler to assume no better
// than 1-byte alignment, and issue sequential byte reads/writes.
typedef union __attribte__((packed)) {
int16_t int16;
uint16_t uint16;
int32_t int32;
@JonathonReinhart
JonathonReinhart / NOTES
Created January 6, 2015 09:05
My working Samba configuration
I had to also do the following items to play nicely with SELinux:
Restore the proper SELinux labels on smb.conf and my smbusers:
# chcon system_u:object_r:samba_etc_t:s0 smb.conf
# chcon system_u:object_r:samba_etc_t:s0 smbusers
Allow Samba to access home dirs:
# setsebool -P samba_enable_home_dirs 1
@JonathonReinhart
JonathonReinhart / zotero.desktop
Created January 28, 2015 08:40
Zotero Desktop Launcher
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Zotero
Exec=/opt/zotero/run-zotero.sh
Icon=/opt/zotero/icons/zotero-new-z-48px.png
Terminal=false
@JonathonReinhart
JonathonReinhart / handletest.c
Last active August 30, 2015 04:16
typedef provides no type safety
#include <stddef.h>
typedef size_t foo_h;
typedef size_t bar_h;
void foo(foo_h h) { (void)h; }
void bar(bar_h h) { (void)h; }
int main(void)
{
@JonathonReinhart
JonathonReinhart / x86_64_regs.c
Created August 30, 2015 08:40
x86-64 registers structure definition
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#define __packed __attribute__((packed))
/* https://commons.wikimedia.org/wiki/File:Table_of_x86_Registers_svg.svg */
#define REGDEF_hl(Z) \
union __packed { \
@JonathonReinhart
JonathonReinhart / oopc.c
Created September 2, 2015 16:32
Object-oriented programming in C (without casts)
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
void *malloc_safe(size_t n)
{
void *p = malloc(n);
if (!p) {
fprintf(stderr, "malloc(%zd) failed\n", n);
abort();
@JonathonReinhart
JonathonReinhart / hexdump.c
Created October 28, 2015 21:39
Hexdump in C
// Derived from http://stackoverflow.com/a/7776146/119527
void fhexdump(FILE *f, const void *addr, size_t len, const char *addrfmt, size_t baseaddr)
{
size_t i;
unsigned char buff[17];
const unsigned char *pc = addr;
// Process every byte in the data.
for (i = 0; i < len; i++) {
@JonathonReinhart
JonathonReinhart / docker_config_temp.sh
Last active February 19, 2016 18:18
Prevent docker client from saving credentials to disk
#!/bin/sh
# This prevents docker config from persisting to disk.
# Place this file in /etc/profile.d/ to happen automatically at login for all users.
# JRR 2015-12-17
# See:
# https://github.com/docker/docker/issues/10318
# https://github.com/docker/docker/issues/18708
dockercfgdir="/dev/shm/dockercfg-$(id -un)"
@JonathonReinhart
JonathonReinhart / .gitconfig
Last active January 22, 2016 14:33
My Git config
[user]
email = jonathon.reinhart@gmail.com
name = Jonathon Reinhart
[color]
ui = true
[core]
# I can exclude my own editor's files; no need to include in project .gitignore
excludesfile = ~/.gitignore_global
editor = vim
[push]
@JonathonReinhart
JonathonReinhart / SConstruct
Last active January 6, 2024 06:42
mkdir -p implemented in C
env = Environment(
CCFLAGS = ['-Wall', '-Werror'],
)
env.Program('mkdir_p_test', ['mkdir_p.c', 'test.c'])