Skip to content

Instantly share code, notes, and snippets.

$itDir = "D:\iTunes Media\Music\"
$dstDir = "D:\Music\"
$ffmpeg = "C:\Users\greg\Downloads\ffmpeg-20170321-db7a05d-win64-shared\bin\ffmpeg.exe"
$itLib = Get-ChildItem -Include @("*.m4a", "*.aac", "*.mp3", "*.flac") -LiteralPath $itDir -Recurse
foreach ($path in $itLib) {
if ((Get-Item -LiteralPath $path.FullName).Attributes -band [IO.FileAttributes]::Directory) {
Write-Output "Directory $($path.FullName)"
} else {
$destPath = ([io.path]::ChangeExtension($path.FullName, "opus")).Replace($itDir, $dstDir)
@valpackett
valpackett / psmdemuxd.c
Created January 30, 2017 07:12
experiments with demultiplexing PS/2 devices (touchpad + trackpoint) on FreeBSD
#include <cuse.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/mouse.h>
@valpackett
valpackett / no-ubt.conf
Created November 26, 2016 14:03
Disable automatic Bluetooth stack loading on FreeBSD (put into /usr/local/etc/devd and restart devd)
# Do nothing when a ubt device is attached
attach 999 {
device-name "ubt[0-9]+";
};
detach 999 {
device-name "ubt[0-9]+";
};
# Do not even load ubt
@valpackett
valpackett / rename_to_timestamp.rb
Created March 5, 2016 14:05
Convert Sweetroll entires' file names to new, date-based format
%w(date json).each { |m| require m }
Dir[File.join ARGV.first, "**/*.json"].each do |path|
fname = File.basename(path)
next if (fname =~ /^\d+-.*/).nil?
pub = (JSON.parse(File.read(path))["properties"] || {})["published"] || []
next if pub.empty?
newpath = File.join File.dirname(path), fname.gsub(/^\d+/, DateTime.parse(pub.first).strftime("%s"))
puts "#{path} => #{newpath}"
File.rename path, newpath
end
@valpackett
valpackett / sandboxed_computation.rs
Last active February 15, 2016 19:46
Early prototype of rusty-sandbox, using a shared memory arena like in sandblast
extern crate libc;
use std::{io, process, mem, ptr};
pub struct Shared<T> {
data: *mut T
}
pub struct SharedArena {
max_size: isize,
@valpackett
valpackett / Gemfile
Last active December 19, 2015 09:09
Ruby: async & thread pool under one EventMachine server
source 'http://rubygems.org'
gem 'thin'
gem 'celluloid'
@valpackett
valpackett / Alfred-Pinboard-INSTANT.md
Last active September 7, 2023 21:01
INSTANT Pinboard search from Alfred 2

INSTANT Pinboard search from Alfred 2

I've had a Python script that makes an HTML Bookmarks file for LaunchBar.
Now that I use Alfred 2, I modified it to make XML for Alfred.
This allows me to search my bookmarks with GREP SPEED!

Installation

First, add your token (from pinboard.in/settings/password) to ~/.netrc

@valpackett
valpackett / require-me-maybe.clj
Last active December 14, 2015 15:49
Clojure macro for executing code if a library exists
(defmacro when-require [n & body]
(let [nn (eval n)]
(try (require nn)
(catch Throwable e nil))
(when (find-ns nn)
`(do ~@body))))
(defmacro if-require [n body1 body2]
(let [nn (eval n)]
@valpackett
valpackett / viewport-fix.js
Created January 5, 2013 17:40
Landscape viewport fix (i.e. makes it 1024px on landscape iPad, 480px on landscape iPhone)
if (typeof window.orientation !== 'undefined') {
var viewport = document.querySelector('meta[name=viewport]');
function isLandscape() {
return window.orientation === 90 || window.orientation === -90;
}
function fixViewport() {
if (isLandscape()) { viewport.content = 'width=device-height' }
else { viewport.content = 'width=device-width' }
}
fixViewport();
@valpackett
valpackett / ClojureRepl.py
Created January 5, 2013 09:58
ClojureRepl
# TryClojure - REPL
import requests
while True:
d = {'expr': raw_input()}
r = requests.get('http://tryclj.com/eval.json', params=d)
if 'result' in r.json:
print(r.json['result'])
else: