Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
ljmccarthy / docker-shell
Created March 2, 2018 16:34
Docker Shell
#!/bin/sh
exec docker run -i -t --rm "$1" /bin/bash
import json
import os
import requests
import sys
import urllib.parse
def google_search(**params):
params = dict(params, source='python', output='json')
response = requests.get('https://serpapi.com/search', params)
if response.status_code != 200:
@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 / cross-compile-musl-cortex-a8.sh
Created August 14, 2018 13:15
Cross-compile musl libc for ARM Cortex A8
#!/bin/sh
export PM=$(grep -c processor /proc/cpuinfo)
# TODO compile LLVM compiler_rt for target
./configure \
--prefix=/ \
--target=armv7a-unknown-linux-eabi \
CC=clang \
@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 / 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>