Skip to content

Instantly share code, notes, and snippets.

View ljmccarthy's full-sized avatar

Luke McCarthy ljmccarthy

View GitHub Profile
@ljmccarthy
ljmccarthy / get-llvm.sh
Last active August 14, 2018 14:57
Get LLVM source code
#!/bin/sh
set -e
set -o pipefail
LLVM_TAG="RELEASE_601"
LLVM_SRC="${HOME}/llvm/src"
get_llvm_project() {
svn export --force "https://llvm.org/svn/llvm-project/${1}/tags/${LLVM_TAG}/final" "${2}"
}
@ljmccarthy
ljmccarthy / settings.json
Last active August 15, 2018 16:12
My settings for VSCode
{
"editor.detectIndentation": false,
"editor.folding": false,
"editor.lineNumbers": "off",
"editor.renderWhitespace": "boundary",
"files.eol": "\n",
"git.autofetch": true,
"git.confirmSync": false,
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
@ljmccarthy
ljmccarthy / build-llvm.sh
Last active August 20, 2018 12:23
Build LLVM
#!/bin/sh
#
# TODO This doesn't work yet
set -e
set -o pipefail
LLVM_SRC="${HOME}/llvm-6.0.1"
LLVM_BUILD="${HOME}/build"
LLVM_INSTALL="${HOME}/sysroot"
#!/bin/sh
for arg in "$@"; do
case $arg in
-c)
exec clang -emit-llvm -flto "$@"
esac
done
exec clang -fuse-ld=lld -flto -static -Wl,--gc-sections -Wl,--strip-all -Wl,--threads "$@"
@ljmccarthy
ljmccarthy / musical_scale.py
Last active August 29, 2018 15:23
Music scale frequency generator
# Music scale frequency generator
# Luke McCarthy 2018-08-29
#
# References:
# https://pages.mtu.edu/~suits/NoteFreqCalcs.html
# https://pages.mtu.edu/~suits/notefreqs.html
# https://en.wikipedia.org/wiki/A440_(pitch_standard)
base_pitch = 440 # A4 = 440Hz (concert pitch)
sample_rate = 44100
#!/bin/sh
CACHEDIR=/tmp/.cache-$USER
mkdir "$CACHEDIR" --mode=700
CHROMECACHEDIR=$CACHEDIR/google-chrome
mkdir "$CHROMECACHEDIR" --mode=700
if [ "`readlink ~/.cache/google-chrome`" != "$CHROMECACHEDIR" ]; then
rm -rf ~/.cache/google-chrome
ln -s "$CHROMECACHEDIR" ~/.cache/google-chrome
@ljmccarthy
ljmccarthy / platformspecific.cpp
Created September 13, 2018 12:01
Platform-specific templates for C++
#include <iostream>
struct Platform {
const char *name;
};
static constexpr Platform Linux{"Linux"};
static constexpr Platform Windows{"Windows"};
template <const Platform *platform>
#!/bin/sh
VERSION="edge"
PLATFORM="x86_64"
DESTDIR=/mnt/d/alpine
sync() {
REPO="$1"
echo "Synchronizing $1..."
rsync --verbose --archive --update --hard-links --delete --delete-after --delay-updates --timeout=600 \
import re
def regex_to_bitset(r):
'''Convert character class into bitset. Assumes ASCII range (0<=ch<=127).'''
bitset = []
for i in range(0, 128, 32):
word = 0
for j in range(i, i+32):
if r.match(chr(j)):
word |= 1 << (j - i)
#!/usr/bin/env python
#
# Displays the average line length from a directory of source files.
#
# Luke McCarthy 2018
from __future__ import print_function
import argparse
import os
import re