Skip to content

Instantly share code, notes, and snippets.

View julius383's full-sized avatar

Julius Kibunjia julius383

View GitHub Profile
#!/usr/bin/env python3
# https://saveandrun.com/posts/2020-04-05-querying-pacman-with-datalog.html
import code
import re
import subprocess
from itertools import starmap
from operator import add
@julius383
julius383 / Makefile
Last active April 6, 2020 06:18
Makefile with rules for running common tasks on Linux
#!/usr/bin/make -f
# vim:ft=make
# https://saveandrun.com/posts/2019-06-27-makefile-madness.html
EXT_UUID = fe3bf9b3-90f9-485c-ba22-5400d8be85c8
EXT_DIR = $(shell findmnt -S UUID=$(EXT_UUID) | tail -1 | cut -f1 -d' ')
CLIPBOARD := $(shell xclip -selection clipboard -o)
TERMINAL := kitty
RSYNCFLAGS=--human-readable --verbose --archive --update --compress --ignore-existing --exclude-from=/home/kaj/.rexclude
@julius383
julius383 / command.py
Last active April 6, 2020 06:18
Custom ranger command to temporarily bind space bar to user specified command
from ranger.api.commands import Command
# https://saveandrun.com/posts/2019-05-07-writing-a-command-for-ranger.html
class bspace(Command):
""":bspace [command sequence]
Temporarily bind a command to the space bar. {file} is
replaced with the currently selected item and {cwd} with
the current working directory.
@julius383
julius383 / rcolor.py
Last active April 6, 2020 06:19
Colour text from stdout based of regular expressions
#!/usr/bin/env python3
"""
color text from stdin based on user specified regular expressions
usage:
command | rcolor.py -p 'regex1' 'regex2' ... 'regexn'
"""
# https://saveandrun.com/posts/2019-03-24-coloring-arbitrary-shell-output.html
@julius383
julius383 / genalgo.c
Last active August 31, 2018 08:31
Genetic algorithm to find expression that evaluates to a given number
/* Check the readme for details */
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
/* Constants */
#define END 0b1111UL
#define TERMS 9 /* Number of terms in a single chromosome */
@julius383
julius383 / math_parser.py
Created April 5, 2018 14:16
Simple math expression parser and evaluater
#!/usr/bin/env python3
import re
OPERATORS = ['+', '-', '/', '*', '(', ')']
"""
Math expression parser and evaluater as explained in
https://lukaszwrobel.pl/blog/math-parser-part-1-introduction/
Expressions are broken up as follows:
@julius383
julius383 / paddle_game.py
Last active April 5, 2018 14:08
SImple implementation of brick-paddle game
#! /usr/bin/env python2
import sys
import pygame
from pygame.locals import *
import itertools
import math
pygame.init()
pygame.font.init()
@julius383
julius383 / get_computer_list.py
Last active April 5, 2018 14:06
Scraper for the top 500 supercomputers in the world from top500.org
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import requests
import pprint
import re
import sys
import yaml
base_url="https://www.top500.org/list/2017/06/?page="
@julius383
julius383 / fetch_names.py
Created March 15, 2018 13:36
Fetch a bunch of names from wikipedia based on the year people with pages were born
#!/usr/bin/env python3
import time
import re
import requests
from bs4 import BeautifulSoup
"""
Gets a list of names based on the year of birth from wikipedia
categories.