Skip to content

Instantly share code, notes, and snippets.

View willeccles's full-sized avatar
🖤
[[maybe_unused]]

Will Eccles willeccles

🖤
[[maybe_unused]]
View GitHub Profile
#! /bin/bash
tempfile=$(mktemp /tmp/cjit.XXXXXXXXXX)
gcc -x c -o "$tempfile" - <<EOL
#include <stdio.h>
int main(void) {
puts("Welcome to the future of programming!");
return 0;
}
/* Compile with -DUSE_READLINE and -lreadline to use readline for input. */
#include <arpa/inet.h>
#include <errno.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
@willeccles
willeccles / package-ringcentral.sh
Last active November 25, 2019 13:20
Package RingCentral Glip as a native Linux Electron app with Nativefier.
#! /bin/bash
# This requires nativefier to be installed, so do that first:
# https://github.com/jiahaog/nativefier
# I know this uses javascript, which is evil, but it must be done :(
# You'll also need to download an image, which is used as input
# for this script. Specify a path to a PNG.
# A .desktop entry is included with this script; you may need to
# modify it depending on where you place the packaged output.
@willeccles
willeccles / spotifylyrics.py
Created October 16, 2019 02:47
Get spotify lyrics for, like, 40% of songs.
#! /usr/bin/env python3
# this script requires beautifulsoup4
# --> pip3 install bs4
# this script also requires requests
# --> pip3 install requests
# TODO make this work on linux
from urllib.request import urlopen
@willeccles
willeccles / const-fibonacci.cpp
Created September 10, 2019 17:04
Compile-time Fibonacci numbers in C++14
// Working example: https://godbolt.org/z/UNnxAy
// Find the nth Fibonacci number
constexpr unsigned fib(unsigned n) {
unsigned a = 0;
unsigned b = 1;
for (unsigned i = 1; i < n; i++) {
a ^= b, b ^= a, a ^= b;
b += a;
}
return a;
@willeccles
willeccles / crc.c
Created August 23, 2019 17:23
crc table
const uint32_t crc[] = {
0, 4c11db7, 9823b6e, d4326d9,
130476dc, 17c56b6b, 1a864db2, 1e475005,
2608edb8, 22c9f00f, 2f8ad6d6, 2b4bcb61,
350c9b64, 31cd86d3, 3c8ea00a, 384fbdbd,
4c11db70, 48d0c6c7, 4593e01e, 4152fda9,
5f15adac, 5bd4b01b, 569796c2, 52568b75,
6a1936c8, 6ed82b7f, 639b0da6, 675a1011,
791d4014, 7ddc5da3, 709f7b7a, 745e66cd,
9823b6e0, 9ce2ab57, 91a18d8e, 95609039,
@willeccles
willeccles / svnsettle.sh
Created August 14, 2019 11:44
Shell script that adds unknown files to SVN and removes missing files from SVN.
#! /bin/bash
# File: svnsettle
# Author: Will Eccles
# Date: 2019-08-14T07:42R
# Description: This script takes any unknown files in an SVN repo (not counting
# ignored ones, obviously) and adds them. If there are any missing files, it
# will remove them from SVN. Note that this is not necessarily a perfect
# solution, but it does what I wanted it to. It's definitely not the cleanest
@willeccles
willeccles / fnkeyfix.sh
Created August 2, 2019 11:44
How to make the Macbook Pro's keyboard F keys work without holding the fn key
#! /bin/bash
# 0 would disable the fn key altogether
# 2 has the effect of setting the keys to be F keys by default
# while still being able to use fn to get play/pause/home/end etc.
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode
@willeccles
willeccles / bmp2arduino.cs
Last active August 12, 2019 23:07
A simple program to convert a Windows bitmap to an Adafruit GFX library bitmap array for monochrome OLED displays.
/*
* bmp2arduino.cs
* Will Eccles 2019
*
* Takes a Windows bitmap file and outputs a C header containing a bitmap array
* to be used with the Adafruit GFX library. Only works for monochrome files at this time.
* All pixels that are not black or transparent are assumed to be white.
*
* Run with no arguments to see usage.
*
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cstdlib>
#include <cstring>
int instr_mov(
const std::string& arg1,