Skip to content

Instantly share code, notes, and snippets.

@DaneWeber
DaneWeber / repo_states.sh
Created September 28, 2017 19:49
Quick status on all git repos in a directory. Based on this answer: https://unix.stackexchange.com/a/394245/63051
# Run the following from a directory containing multiple git repositories
# The `28` in the printf command is arbitrary and just matches the number of characters in the longest-named repo I have.
function repo_states () {
for repo in */; do
printf '%-28s' "$repo"
( cd "$repo" && git status --short --branch --untracked-files=no )
done
}
@DaneWeber
DaneWeber / swagger2pdf-Makefile
Last active October 30, 2018 20:28
Makefile command to use docker images for swagger2markdown piped to asciidoctor
# swagger2markup output fed to asciidoctor-pdf - all via published docker images
# The following is a Makefile command in the root of a web service repo with the following assumptions:
# ./swagger/v1/swagger.json is the swagger definition (created by rswag in my case)
# ./_docs/ is where we want the PDF and intermediate ADOC to live
# The ADOC file is pretty useful, but if you just want the PDF, it's a byproduct you might want to clean up
api_pdf:
docker run --rm -v $(shell pwd):/opt swagger2markup/swagger2markup convert -i /opt/swagger/v1/swagger.json -f /opt/_docs/api-definition
docker run --rm -v $(shell pwd)/_docs:/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf api-definition.adoc
@DaneWeber
DaneWeber / create-minecraft-sync-task.ps1
Created September 10, 2018 17:23
Sync Minecraft saves via cloud syncing solution like OneDrive
$syncScript = $PSScriptRoot + "\sync-minecraft-saves.ps1"
$minuteRepeat = 10
schtasks /create /sc minute /mo $minuteRepeat /ru System /tn "Minecraft Save Sync" /tr "powershell.exe -NoLogo -WindowStyle hidden -file $syncScript"
@DaneWeber
DaneWeber / nightRoute.rb
Created August 2, 2018 15:29
2018-08-02 Bits, Please! Code Fight
def nightRoute(city)
final = city.length - 1
hops = {}
hops[0] = city[0].each_with_index.map{ |length, island| length == -1 ? nil : [0, island] }.compact
(1..final).each do |iter|
hops[iter] = hops[iter - 1].map do |path|
if path[-1] == final
nil
else
city[path[-1]].each_with_index.map do |length, island|
@DaneWeber
DaneWeber / perfectCity.rb
Created July 26, 2018 15:15
2018-07-26 Bits, Please! Code Fight
def perfectCity(departure, destination)
diff(departure[0], destination[0]) + diff(departure[1], destination[1])
end
def diff(dep, dest)
naiveDiff = (dep - dest).abs
extraDiff = 0
if dep.ceil == dest.ceil
lower, higher = [dep, dest].sort
extraDiff = [lower - lower.floor, higher.ceil - higher].min * 2
@DaneWeber
DaneWeber / Jenkinsfile
Created July 15, 2018 04:01
Conflict Manager - check git branches for conflicts early and often
// This defines a cron trigger for a scripted Jenkinsfile:
properties([pipelineTriggers([cron('*/10 8-22 * * 1-5')])])
node {
stage('Checkout Repo with Script') {
checkout scm
}
dir('conflict-checker') {
stage('Check branches for merge conflicts') {
// These were defined in the Jenkinsfile for my particular needs, but don't have to be.
@DaneWeber
DaneWeber / AHK-LiteralTabPaste.ahk
Last active April 7, 2016 17:03
Literal paste of tabular data into Excel via AHK hotkey
#z:: ; Text–only paste from ClipBoard
KeyWait, LWin
KeyWait, RWin
Clip0 = %ClipBoardAll% ; Save formatted text for later
ExcelBound = %Clipboard%
Loop, parse, ExcelBound, `r`n
{
if A_LoopField =
continue
nonemptyline := A_LoopField
@DaneWeber
DaneWeber / AHK-Excel-Paste.ahk
Created April 4, 2016 17:09
Especially when you have hidden rows/columns, this pastes into the visible cells, based on tabs and new lines.
#z::
KeyWait, LWin
KeyWait, RWin
Clip0 = %ClipBoardAll% ; Save formatted text for later
ExcelBound = %Clipboard%
Loop, parse, ExcelBound, `r`n
{
if A_LoopField =
continue
nonemptyline := A_LoopField
@DaneWeber
DaneWeber / WordFindAllInstances
Created November 26, 2013 17:34
Find All Instances of the match value. You can see the results inserted into the "Immediate" debug area. Press Ctrl+G if you don't see it. See this page if you don't know how to install a macro: http://www.gmayor.com/installing_macro.htm
Option Explicit
Sub FindAllInstances()
Dim MyAR() As String
Dim i As Long
Dim match As String
match = "has"
i = 0
@DaneWeber
DaneWeber / Magic-Button-Masher.ahk
Created September 23, 2013 17:33
This is my attempt at a program that will allow you to type randomly on the keyboard and have pre-determined text entered instead. This can be useful when performing live demonstrations or when you want to impress someone (ha!). Started as a response to a question on SuperUser: http://superuser.com/questions/642041/hacker-typer-style-application…
#UseHook ; Avoid loops of the Send command triggering the hotkey again.
AutoTrim, Off ; Don't auto-trim spaces and tabs from the beginning and end of the sourcetext.
SendMode InputThenPlay ; Try to prevent the user from corrupting the buffer text.
SetWorkingDir %A_ScriptDir%
Suspend, On ; Start suspended
FileRead, MasherBuffer, magic-button-masher-text.txt
if ErrorLevel
MasherBuffer = Type or paste text here. You can also drag-and-drop text files here.