Skip to content

Instantly share code, notes, and snippets.

View ljmccarthy's full-sized avatar

Luke McCarthy ljmccarthy

View GitHub Profile
@ljmccarthy
ljmccarthy / split_with_quoted_strings.py
Created August 6, 2014 15:18
Split string without splitting embedded quoted strings and maintaining quotes.
import re
re_quoted_string = re.compile(r"(\"(?:\\\"|[^\"])*\"|'(?:\\'|[^'])*')")
def split_with_quoted_strings(s):
"""Split string without splitting embedded quoted strings."""
return [x.strip() for x in re_quoted_string.split(s) if x.strip()]
for x in split_with_quoted_strings('hello "world \\\"blah" \'x y z\' blah'):
print(x)
@ljmccarthy
ljmccarthy / factorial_mpdecimal.c
Created August 18, 2014 19:24
Compute factorial(1000) with mpdecimal
#include <stdio.h>
#include "mpdecimal.h"
int main()
{
mpd_context_t ctx;
mpd_t *a, *b, *c;
mpd_maxcontext(&ctx);
@ljmccarthy
ljmccarthy / factorial_tommath.c
Last active August 29, 2015 14:05
Compute factorial(1000) with libtommath
#include <stdio.h>
#include "tommath.h"
int main()
{
mp_int a, b, c;
mp_init(&a);
mp_init(&b);
mp_init(&c);
import sys
from decimal import Decimal, ROUND_UP
def ebay_postage_price(p):
d = p * (1 / (1 - Decimal('0.134'))) + Decimal('0.20')
return d.quantize(Decimal('0.1'), rounding=ROUND_UP)
for x in sys.argv[1:]:
print(format(ebay_postage_price(Decimal(x)), '.2f'))
$ sudo pacman -Rc systemd
checking dependencies...
:: alsa-plugins optionally requires libpulse: PulseAudio plugin
:: alsa-plugins optionally requires ffmpeg: libavcodec resampling plugin, a52 plugin
:: alsa-tools optionally requires gtk2: other GUI tools
:: alsa-tools optionally requires gtk3: hdajackretask
:: avahi optionally requires gtk3: avahi-discover-standalone, bshell, bssh, bvnc
:: avahi optionally requires gtk2: gtk2 bindings
:: avahi optionally requires qt4: qt4 bindings
@ljmccarthy
ljmccarthy / .Xresources
Last active December 13, 2015 13:17
My rxvt-unicode configuration
URxvt*.buffered: true
URxvt*.transparent: true
URxvt*.shading: 30
URxvt*.background: black
URxvt*.foreground: white
URxvt*.font: xft:DejaVu Sans Mono:size=10
URxvt*.scrollstyle: plain
URxvt*.scrollBar_right: true
*color0: #2E3436
@ljmccarthy
ljmccarthy / display_ppi.py
Last active December 20, 2015 13:39
Calculate display PPI (pixels per inch) given resolution, aspect ratio and diagonal size.
# Calculate display PPI (pixels per inch) given resolution, aspect ratio and diagonal size.
# Luke McCarthy 2013-08-02
import math
def display_ppi(resolution, aspect_ratio, size_inches):
res_h, res_v = resolution
aspect_h, aspect_v = aspect_ratio
theta = math.atan(float(aspect_v) / aspect_h)
width = math.cos(theta) * size_inches
@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 / 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 \