Skip to content

Instantly share code, notes, and snippets.

@cmccandless
cmccandless / exercise-data.json
Created January 11, 2018 21:58
exercism/python exercise data
{
"loops": [
{
"slug": "armstrong-numbers",
"difficulty": 1
},
{
"slug": "atbash-cipher",
"difficulty": 1
},
@cmccandless
cmccandless / sudoku.py
Last active February 28, 2018 15:57
Sudoku solver
def valid(puzzle):
m = [list(row) for row in puzzle.split('\n')]
for row in m:
counts = set()
for ch in row:
if ch in counts and '_' != ch:
return False
counts.add(ch)
for column in zip(*m):
counts = set()
@cmccandless
cmccandless / set_ps1.sh
Last active October 5, 2018 14:54
Bash prompt
#!/bin/bash
# Custom bash prompt
# Usage: add `source set_prompt.sh` to your .bashrc
# Settings: 0 or 1
DEBUG=0
USE_16M_COLOR=1
# lowercase: decimal
# uppercase: hexadecimal
@cmccandless
cmccandless / update_tests.py
Last active March 2, 2018 14:06
Script for downloading the latest test suites for Exercism tracks
#!/usr/bin/env python
import argparse
import os
from glob import glob
from urllib.request import urlretrieve
from urllib.error import HTTPError
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
@cmccandless
cmccandless / hostscan.sh
Created March 20, 2018 16:41
Nmap LAN host scan
#!/bin/sh
nmap -sVL 192.168.1.1-127 |
grep -v "for 192.168.1." |
grep -oP "(?<=for ).*"
@cmccandless
cmccandless / argparse_completion.py
Last active June 4, 2018 18:48
Generated Zsh/Bash Autocompletion for argparse.ArgumentParser
import argparse
from itertools import chain
def get_parser_info(parser):
opts = {}
commands = {}
if parser._positionals and parser._positionals._actions:
for a in parser._positionals._actions:
if isinstance(a, argparse._StoreAction) and not a.option_strings:
@cmccandless
cmccandless / ifconfig_completion.bash
Created April 24, 2018 18:02
ifconfig bash completion
_ifconfig()
{
local cur prev interfaces
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "${COMP_CWORD}" in
1) interfaces=$(ifconfig | grep -oP "^\w+") ;;
esac
@cmccandless
cmccandless / loop
Created May 9, 2018 18:27
Simple loop command
#!/usr/bin/env python
from __future__ import print_function
import argparse
import subprocess
import sys
parser = argparse.ArgumentParser(
prog='loop',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
@cmccandless
cmccandless / make_github_issue.py
Last active August 6, 2018 13:02 — forked from JeffPaine/make_github_issue.py
Make an issue on github using API V3 and Python
# -*- coding: utf-8 -*-
# Uses Python 2.7
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import requests
import json
@cmccandless
cmccandless / usbaudioctl.sh
Last active August 28, 2018 18:19
Switch USB Audio mode (Headset <-> Speaker) on Ubuntu 16.04
#!/bin/bash
set -e
# CARD=1
PROFILE_BASE=output:analog-stereo
DEVICE=usb-Generic_USB_Audio_200901010001-00
CARD_NAME="alsa_card.${DEVICE}"
SINK_BASE="alsa_output.${DEVICE}.analog-stereo"
# Find card index