Skip to content

Instantly share code, notes, and snippets.

@iley
iley / part1.awk
Last active December 4, 2021 07:11
Advent of Code Day 4
function has_won(board, x, y, winning_row, winning_col) {
for (y = 1; y <= height; y++) {
winning_row = 1
for (x = 1; x <= height; x++) {
if (board[x, y] != -1) {
winning_row = 0
break
}
}
@iley
iley / part1.awk
Created December 3, 2021 08:57
Advent of Code Day 3
BEGIN { FS="" }
{
for (i = 1; i <= NF; i++) {
if ($i == 1) ones[i]++
else zeroes[i]++
}
}
END {
@iley
iley / switchout.sh
Created March 25, 2012 08:18
Change output device in pulseaudio
#!/usr/bin/env bash
sinks=($(pacmd list-sinks | grep index | \
awk '{ if ($1 == "*") print "1",$3; else print "0",$2 }'))
inputs=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
[[ ${sinks[0]} = 0 ]] && swap=${sinks[1]} || swap=${sinks[3]}
pacmd set-default-sink $swap &> /dev/null
for i in ${inputs[*]}; do pacmd move-sink-input $i $swap &> /dev/null; done
@iley
iley / awsp.sh
Created January 17, 2020 09:46
Script to switch AWS between profiles configured with SSO
#!/bin/bash
set -e
new_profile="$1"
if [[ -z "$new_profile" ]]; then
# Just list existing profiles.
profiles=$(cat ~/.aws/config | perl -ne 'print if s/\[profile\s+(\S+)\]/$1/')
default_account=$(aws configure get sso_account_id --profile default)
for profile in $profiles; do
#include <LiquidCrystal.h>
#include <Wire.h>
const int speakerPin = 9;
const int lampPin = 8;
const int controlButtons = 3;
const int controlButtonPins[] = { 12, 13, 11 };
const int playerButtons = 6;
const int playerButtonPins[] = { 5, 4, 3, 2, 1, 0 };
@iley
iley / gist:1490213
Created December 17, 2011 13:30
Perl tips
Perlbrew — install multiple perl environments in $HOME
Bundle::Zoidberg — modular perl shell
Devel::REPL + Term::ReadLine::Perl + Term::ReadKey = handy REPL
Devel::Trace — print out each line before it is executed
use autodie
Module::UseFrom — use module from string
List::MoreUtils (List::AllUtils = List::Util + List::MoreUtils)
Params::Util - check parameter types properly (http://perladvent.org/2011/2011-12-23.html)
Try::Tiny — sugar for eval
import random
from collections import defaultdict
class LoadBalancer:
def __init__(self, targets, probabilities):
self._targets = targets.copy()
n = len(targets)
self._n = n
p = probabilities.copy()
self._alias = [0] * n
@iley
iley / Vagrantfile
Last active July 18, 2018 11:09
basic vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<-SCRIPT
echo Provisioning...
sed 's/^session.*pam_motd/# &/' -i /etc/pam.d/{sshd,login}
sed 's/^AcceptEnv LANG/# &/' -i /etc/ssh/sshd_config
sudo apt update
SCRIPT
@iley
iley / build.log
Created March 31, 2011 11:02
OpenCV build log
macserver:build_device iley$ SDK_VERSION=4.3 ../opencv_cmake.sh device ../OpenCV-2.1.0
Starting cmake...
Target SDK = iPhoneOS
iOS SDK Version = 4.3
iOS Deployment Target = 3.0
OpenCV Root = ../OpenCV-2.1.0
OpenCV Install Prefix = /Users/iley/Sources/iphone_opencv_test/build_device/../opencv_device
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
if [ -z "$WORKON_HOME" ]; then
export WORKON_HOME="$HOME/.virtualenvs"
fi
workon () {
virtualenv="$1"
if [ -z "$virtualenv" ]; then
echo "Usage: workon env_name" >&2
return 1
fi