Skip to content

Instantly share code, notes, and snippets.

@brake
brake / Iterm2_NeoVIM.scpt
Created June 28, 2023 15:52
iTerm2 open files in neovim opened in new tab
on run argv
# seem to need the full path at least in some cases
set nvimCommand to "/usr/local/bin/nvim "
set filepaths to ""
if argv is not {} then
repeat with currentFile in argv
set filepaths to filepaths & quoted form of POSIX path of currentFile & " "
end repeat
@brake
brake / example.py
Created December 19, 2019 12:14
IO wrapper for intercepting of stdout and stderr into log file managed by logging framework
from contextlib import redirect_stderr, redirect_stdout
from logging import getLogger
from logging_io import LoggingErrorOutput, LoggingInfoOutput
logger = getLogger()
error_output = LoggingErrorOutput(logger)
normal_output = LoggingInfoOutput(logger)
with redirect_stdin(normal_output), redirect_stdout(error_output):
@brake
brake / git-pushing-multiple.rst
Created October 13, 2019 18:49 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

If in doubt about what git is doing when you run these commands, just

@brake
brake / executableJarPath.kt
Created February 14, 2019 13:06
Get executable jar path on Kotlin
fun getExecutablePath(): File? =
Paths.get(object {}.javaClass.protectionDomain.codeSource?.location?.toURI()).parent.toFile()
@brake
brake / SuccessOrFailure.java
Created February 3, 2018 19:26
Java Union type snippet
final class SuccessOrFailure extends Union<String, SomeErrorType> {
private SuccessOrFailure(final String result, final SomeErrorType someError) {
super(result, someError);
}
public static SuccessOrFailure createFromSuccess(final String result) {
return new SuccessOrFailure(result, null);
}
@brake
brake / random-bytes.clj
Created December 22, 2017 18:21
Generate random bytes (hex encoded)
(import [javax.xml.bind DatatypeConverter])
(defn random-bytes-hex
[n]
(->> (repeatedly n (fn [] (rand-int 255)))
(map unchecked-byte)
byte-array
(DatatypeConverter/printHexBinary)))
@brake
brake / GoogleSheetsDate.java
Created December 1, 2017 06:52
Java Date to Google Sheets Date converter
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class GoogleSheetsDate {
private static final long SHEETS_EPOCH_DIFFERENCE = 2209161600000L;
static double fromJavaDate(Date date) {
// https://stackoverflow.com/a/38015954/5525962
long millisSinceUnixEpoch = date.getTime();
long millisSinceSheetsEpoch = millisSinceUnixEpoch + SHEETS_EPOCH_DIFFERENCE;
@brake
brake / default.txt
Created October 31, 2017 17:39
GSM 7 bit alphabet ETSI TS 123 038
@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\uFFFFÆæßÉ !"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà
@brake
brake / smartCard.java
Created May 31, 2017 16:52
Typical Java SmartCard workflow
TerminalFactory terminalFactory = TerminalFactory.getDefault();
CardTerminals terminals = terminalFactory.terminals();
List<CardTerminal> terminalsList = terminals.list();
CardTerminal terminal = terminalsList.get(0);
Card card = terminal.connect("T0");
(defn swap-nibbles
[s]
(->> s
(partition 2)
(map reverse)
flatten
(apply str)))