Skip to content

Instantly share code, notes, and snippets.

@alwalker
alwalker / pooORM.cs
Last active August 29, 2015 14:02
The Worlds Smallest ORM For People Who Hate ORM's
public class DAOBase
{
private readonly string _connectionString;
public DAOBase(string database)
{
try
{
_connectionString = ConfigurationManager.ConnectionStrings[database].ConnectionString;
}
@alwalker
alwalker / tmk.sh
Last active August 29, 2015 14:21
Stuff for setting up TMK based builds.
sudo apt-get install gcc-avr gdb-avr binutils-avr avr-libc avrdude libusb-1.0-0-dev dfu-util
#git your flavor of tmk, for example
#git clone https://github.com/jackhumbert/tmk_keyboard
cd ~/code/others
git clone https://github.com/dfu-programmer/dfu-programmer.git
cd dfu-programmer
./bootstrap.sh
./configure
@alwalker
alwalker / tagger.py
Created July 10, 2012 12:46
mp3 tagger
import os
import eyeD3
trackNo = 1
listing = os.listdir(".")
for infile in listing:
maxt = listing.count
title = " ".join(" ".join(str(infile).split(' ')[1:]).split('.')[:-1])
print title
tag = eyeD3.Tag()
@alwalker
alwalker / flac_to_mp3_car.ps1
Last active December 13, 2015 23:38
Powershell script for converting flac files to low quality mp3's for use in car stereo. Replaces artist tags with album artist information for easy navigation in car audio systems.
clear
$files = get-childitem "F:\Work_Area\Music\Raw" *.flac -rec
foreach ($file in $files)
{
$artist = metaflac $file.fullname --show-tag=ALBUMARTIST
if(!$artist -or !$artist.split("=")[1]) {$artist = metaflac $file.fullname --show-tag=ARTIST}
$artist = $artist.split("=")
$artist = $artist[1..($artist.length-1)] -join "="
@alwalker
alwalker / sql_express_full_backup_and_cleanup.ps1
Created January 26, 2016 14:42
Script for taking a full backup of a sql express database then cleaning up the previous weeks backups
$limit = (Get-Date).AddDays(-8)
sqlcmd -S pmssql -E -Q "EXEC sp_BackupDatabases @backupLocation='D:\backups\', @backupType='F', @databaseName='dashboard'"
if ($LASTEXITCODE -eq 0) {
$path = "D:\backups"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
# Delete any empty directories left behind after deleting the old files.
@alwalker
alwalker / couch_replication.sh
Created July 18, 2016 20:03
Keep your CouchDB databases synchronized between two servers
#!/bin/bash
#CouchDB replication sync script.
#Run on target CouchDB server and supply IP or DNS name of source.
#For example running 'bash couch_replicator.sh tcdb01' on tcdb02
#will keep tcdb02 in sync with all databases on tcdb01.
if [ "$#" -ne 1 ]; then
echo "Wrong number of arguments!"
@alwalker
alwalker / view_rebuilder.rb
Created July 18, 2016 20:10
Rebuild your CouchDB Views
require 'pry'
require 'couchrest'
require 'net/http'
require 'uri'
require 'json/ext'
require 'rest-client'
if ARGV.length == 1
puts 'Run on all database (y/n)?'
if STDIN.gets.chomp != 'y'
@alwalker
alwalker / media_server.sh
Last active July 30, 2017 01:51
Instructions for building a media box with NZBGet + Sonarr + Couchpotato + Headphones + Plex
#disable password access /etc/ssh/sshd_config
#set to no password 'ALL=NOPASSWD: ALL'
#change /etc/network/interfaces
#reboot
#update sources
sudo apt-get update
sudo apt-get upgrade
#reboot
#needed packages
sudo apt-get install git nfs-common python-lxml python-pip libffi-dev libssl-dev mono-devel open-vm-tools atop
IS_LOCKED=$(sudo lsof /var/lib/dpkg/lock | wc -l)
echo "Is Locked? $IS_LOCKED"
until [[ $IS_LOCKED -eq 0 ]]; do
echo "Is Locked? $IS_LOCKED"
echo "sleeping for 5"
sleep 5
IS_LOCKED=$(sudo lsof /var/lib/dpkg/lock | wc -l)
done
@alwalker
alwalker / yum_dep_finder.sh
Created May 14, 2018 14:44
Find yum repos that you're using based on actually installed packages
yum repolist | grep -Po "^[\w|-]+(?=\/)" | xargs yumdb search from_repo | grep -Po "=\K .+" | sort - | uniq - | sed -e 's/^[[:space:]]*//' | awk '{system("repoquery --repoid="$1" -a --location")}' | grep -oP "^.+\://\K[^/]+(?=/.+)" | sort - | uniq - | awk '{system( "echo && host "$1)}'