Skip to content

Instantly share code, notes, and snippets.

View ljmccarthy's full-sized avatar

Luke McCarthy ljmccarthy

View GitHub Profile
TARGET = myprogram
SRCDIRS = src
INCDIRS = include
OBJDIR = /tmp/myprogram-build
LIBDIRS =
LIBS =
DEFINES =
PKGS =
CFLAGS = -std=c++98 -Wall -W -fvisibility=hidden -fvisibility-inlines-hidden
LINKFLAGS =
@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 / youtube_screen_scrape.py
Last active March 24, 2021 01:11
An example of how to download metadata for all videos of a specified YouTube channel using simple BeautifulSoup screen scraping. The data will be much more up-to-date and reliable than the RSS feed or YouTube API results (which is a sad state of affairs really).
import urllib
import json
from bs4 import BeautifulSoup
from collections import namedtuple
Video = namedtuple("Video", "video_id title duration views thumbnail")
def parse_video_div(div):
video_id = div.get("data-context-item-id", "")
title = div.find("a", "yt-uix-tile-link").text
@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 / qemu-winxp.sh
Created November 28, 2015 18:31
QEMU command line for Windows XP
#!/bin/sh
exec qemu-system-i386 -enable-kvm -cpu host -m 1024 -vga std -soundhw ac97 -net nic,model=rtl8139 \
-net user -drive file=winxp.img,format=raw -drive file=/usr/share/virtio/virtio-win.iso,media=cdrom
@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