Skip to content

Instantly share code, notes, and snippets.

@btm
btm / google_takeout_music_rename.rb
Created March 31, 2021 23:34
Script to rename Google Takeout Youtube music uploads
# terrible script for reading the music-uploads-metadata.csv file that Google Takeout includes when you download
# Youtube Music 'uploads' (which were Google Play Music songs/uploads).
#
# tries to identify the corresponding file and add artist/album/track to the mp3 tags
# use another tool like MediaMonkey afterward to rename the files, add cover art, etc.
#
# It's hard to separate tracks with the same name. Deal with them by hand.
#
# This worked for about 90% of my mp3s. Your mileage may vary. No promises or guarantees.
# This is hacked together. Works for me. Use at your own risk.
@btm
btm / gist:6700524
Last active February 26, 2024 01:10
Why curl | sudo bash is good: it is simple single line, and uses the same channel that downloading a repository signing key would.

Easy one line Chef installation for all platforms (except windows)

curl https://www.opscode.com/chef/install.sh | sudo bash

That's it. This can be put in any instructions, such as a README or someone's blog, since the logic is in the shell script. Provided you download the script using https, the file has standard levels of authentication and encryption protecting it from manipulation.

This is obviously a shell script, if you're really concerned about the argument that it may contain nefarious activities within, you can easily review it before you run it.

@btm
btm / gist:6233398
Created August 14, 2013 17:35
Using grep against STDERR
# This error goes to STDERR
$ asdfasdf
-bash: asdfasdf: command not found
# We redirect STDERR to STDOUT, but STDOUT to null, so we can use grep against STDERR
$ asdfasdf 2>&1 >/dev/null | grep -q not ; echo $?
0
PS C:\users\btm\Documents\dcom> Get-CimInstance -ClassName Win32_DCOMApplicationSetting -Property * -Filter 'AppID="{37399C92-DC3F-4B55-AE5B-811EE82398AD}"' |fl
Caption : AppServiceContainerBroker
Description : AppServiceContainerBroker
SettingID :
AppID : {37399c92-dc3f-4b55-ae5b-811ee82398ad}
AuthenticationLevel :
CustomSurrogate :
EnableAtStorageActivation : False
@btm
btm / A-launchctl_parse.rb
Last active June 4, 2020 23:48
parsing 'launchctl print' even though apple says not to because we are wild and crazy kids
require "pp"
WORD_REGEX = '([\w.:\/\(\)" -]+)' # basically match everything but [{}=>]
launchctl_output = `launchctl print system/com.opscode.chef-client`
hash = { }
hash_index = [ ]
launchctl_output.each_line do |line|
case line
@btm
btm / gist:7cb421f5fe7d1003083a
Created March 18, 2015 22:00
Chef Postmortem Template
# INCIDENT DATE - INCIDENT TYPE
## Meeting
#### Waiving meetings
In some cases the IC might determine that a PM meeting for the incident isn't needed.
If the IC decides to waive the meeting please replace the `Meeting` section with a
note indicating the meeting has been waived (example: `Meeting waived: Paul Mooring`)
@btm
btm / wua.rb
Created October 27, 2014 18:49
Determine if a KB is installed via win32ole on ruby
# Author:: Bryan McLellan <btm@loftninjas.org>
# Copyright:: Copyright 2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@btm
btm / ec2_fetchkey
Created May 30, 2013 22:46
FreeBSD + Openstack Notes
#!/bin/sh
# PROVIDE: ec2_fetchkey
# REQUIRE: NETWORKING
# BEFORE: LOGIN ec2_firstboot
# Define ec2_fetchkey_enable=YES in /etc/rc.conf and create /root/firstboot
# to enable SSH key fetching when the system next boots.
#
: ${ec2_fetchkey_enable=NO}
@btm
btm / check_installed.rb
Last active January 4, 2016 20:19
utilities for getting microsoft installer product code data from ruby
# Reads a product code from an MSI file
# Checks if that product code is installed on the system
require 'rubygems'
require 'ffi'
require 'pathname'
PRODUCT_CODE_LENGTH = 38
module Win32
@btm
btm / README.md
Last active December 31, 2015 02:39
Could a well timed network failure turn curl | bash into a destructive accident?

There is an assertation that one reason the "curl | sudo bash" pattern is bad is because you may experience network failure and execute a partially downloaded script.

This:

rm -rf /tmp/random_directory

Could accidentally become:

rm -rf /