Skip to content

Instantly share code, notes, and snippets.

def pad_or_trim(mat, required_len):
if mat.shape[0] < required_len:
return np.pad(mat, ((0, required_len - mat.shape[0]), (0, 0)), 'constant')
if mat.shape[0] > required_len:
return mat[:required_len]
return mat
@valpackett
valpackett / global-input-unstable-v1.xml
Last active November 20, 2022 18:40
global-input wayland protocol DRAFT PREVIEW
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="global_input_v1">
<copyright>
Copyright (C) 2017 Val Packett ([email protected])
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@valpackett
valpackett / README.md
Created September 6, 2017 21:49
FreeBSD Vulkan info log
#!/usr/bin/env run-cargo-script
//! ```cargo
//! [dependencies]
//! unixbar = "0"
//! systemstat = "0"
//! ```
#[macro_use] extern crate unixbar;
extern crate systemstat;
use unixbar::*;
@valpackett
valpackett / nvim-bloaty
Created April 28, 2017 18:00
bloaty report for neovim 0.1.7 from freebsd official pkgs
$ bloaty $(which nvim)
VM SIZE FILE SIZE
-------------- --------------
75.8% 1.84Mi .text 1.84Mi 77.1%
10.2% 253Ki .rodata 253Ki 10.4%
5.3% 130Ki .eh_frame 130Ki 5.3%
4.6% 113Ki .data 113Ki 4.6%
1.9% 47.4Ki .bss 0 0.0%
1.2% 30.0Ki .eh_frame_hdr 30.0Ki 1.2%
0.3% 6.61Ki .dynsym 6.61Ki 0.3%
@valpackett
valpackett / dump.json
Created April 28, 2017 17:44
my geekedin profile
{
"_id": "d08a4d8d-5c30-42a7-a6fe-42af3d3243da1448627578734",
"_class": "com.geekedin.domain.entities.mongo.EDeveloper",
"scores": [
{
"technology": "CSS",
"score": 1141,
"lastCompute": {
"sec": 1470051310,
"usec": 552000
$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