Skip to content

Instantly share code, notes, and snippets.

View lautarodragan's full-sized avatar

Taro lautarodragan

View GitHub Profile
@lautarodragan
lautarodragan / p4backup.bat
Created March 20, 2024 23:02
Perforce Backup
@echo off
::::: p4backup.bat :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: A tiny Windows Batch Script to backup a Perforce Server
::
:: arguments:
:: (none)
::
:: usage:
@lautarodragan
lautarodragan / p4ftp.bat
Last active March 20, 2024 23:03
Perforce FTP Backups
@echo off
::::: p4ftp.bat :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: A little Windows Batch Script to upload a Perforce ChangeList from console to a FTP host
::
:: first argument is the change list number, and is mandatory.
:: second argument is an optional "1" flag, indicating no confirmation is desired.
::
:: usage (from console): p4ftp.bat <cl> [1]
type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends Record<string, unknown>
? DeepReadonly<T[P]>
: T[P];
};
@lautarodragan
lautarodragan / README.md
Last active May 15, 2023 14:08
Pop!_OS Theme Toggle Keyboard Shortcut

Pop!_OS Theme Toggle Keyboard Shortcut

This script toggles both the Pop!_OS theme between Pop-dark and Pop and the gnome color-theme preference between prefer-light and prefer-dark at once. We need to toggle both because some apps use one and some the other. In particular, the CSS feature that allows detection of user preferences uses org.gnome.desktop.interface color-scheme, while native apps mostly use the gtk-theme.

To use it, you could just run the script manually from a terminal (. theme-toggle.sh or chmod a+x theme-toggle.sh and then ./theme-toggle.sh), but that's no fun.

Instead, you can add a desktop-wide keyboard shortcut that triggers this script.

To do so, open Settings (gnome-control-center) and go to Keyboard > Keyboard Shortcuts > View and Customize Keyboard Shortcuts.

@lautarodragan
lautarodragan / awsotp.md
Last active June 8, 2023 19:18
AWS CLI + Yubikey

Install YubiKey Manager

Yubico docs: https://developers.yubico.com/yubikey-manager/

Right now, Yubico distributes yubikey-manager under the official ppa yubico/stable for apt. Double-check this is still the case when you're reading this guide — you don't want to trust a non-official distribution of yubikey-manager.

sudo apt-add-repository ppa:yubico/stable
sudo apt update
sudo apt install yubikey-manager
@lautarodragan
lautarodragan / MyHappyProto.proto
Last active January 30, 2023 15:41
protobuf.js wrapper types + null
syntax = "proto3";
import "google/protobuf/wrappers.proto";
message MyHappyProto {
string id = 1;
google.protobuf.StringValue name = 2;
google.protobuf.StringValue address = 3;
google.protobuf.StringValue something = 4;
google.protobuf.StringValue nullable = 5;
@lautarodragan
lautarodragan / README.md
Last active October 30, 2022 02:08
Letter Frequency

This mini-project compares frequencies of letters in the English language in general and an extract from Frank Herbert's Dune.

The average letter frequencies can be found in letter-frequencies.json. This file is a JSON object mapping letters to frequencies, and looks like this:

{
  "E": 11.1607,
  "M": 3.0129,
  "A": 8.4966,
  "H": 3.0034,
@lautarodragan
lautarodragan / index.js
Created July 11, 2019 06:20
Bitcoin Private Key to WIF
// https://en.bitcoin.it/wiki/Wallet_import_format
const crypto = require('crypto');
const base58 = require('base-58')
const sha256 = buffer => crypto.createHash('sha256').update(buffer).digest()
const privateKeyToWIF = (privateKey, prefix = 'ef', compressed = '01') => {
const prefixedPrivateKey = prefix + privateKey + compressed
const prefixedPrivateKeyBuffer = Buffer.from(prefixedPrivateKey, 'hex')
@lautarodragan
lautarodragan / index.ts
Created May 15, 2019 03:42
ethereumjs-util @types/bn.js issue
import { bufferToHex, ecrecover, fromRpcSig, hashPersonalMessage, publicToAddress } from 'ethereumjs-util'
export function signatureIsValid(address: string, message: string, signature: string): boolean {
const msgHash = hashPersonalMessage(Buffer.from(message))
const signatureParams = fromRpcSig(signature)
const publicKey = ecrecover(
msgHash,
signatureParams.v,
signatureParams.r,
@lautarodragan
lautarodragan / jsonld-factory.js
Last active September 28, 2018 08:46
Using jsonld as a factory rather than a singleton
const JSONLD = require('jsonld')
const jsonld = JSONLD // try commenting this line
// const jsonld = JSONLD() // and uncommenting this one
const DefaultClaimContext = {
cred: 'https://w3id.org/credentials#',
schema: 'http://schema.org/',
sec: 'https://w3id.org/security#',