Skip to content

Instantly share code, notes, and snippets.

View jmg-duarte's full-sized avatar
📦
Producing blocks...

José Duarte jmg-duarte

📦
Producing blocks...
View GitHub Profile
use std::{io::Cursor, str::FromStr};
use cid::Cid;
use codec::{Decode, Encode, IoReader};
use storagext::{
runtime::runtime_types::pallet_market::pallet::DealProposal as RtDealProposal,
types::market::DealProposal, BlockNumber, Currency,
};
use subxt::ext::sp_runtime::AccountId32;
@jmg-duarte
jmg-duarte / GlobalShortcutMacOS.swift
Created December 31, 2024 15:52
Function to setup global shortcuts in MacOS apps - somewhat incomplete, written before moving to HotKeys
/// Sets up the global shortcuts (currently, just Cmd+Shift+ç)
///
/// References:
/// https://developer.apple.com/forums/thread/707680?answerId=716892022#716892022
/// https://developer.apple.com/documentation/coregraphics/cgevent/1454426-tapcreate
/// https://stackoverflow.com/a/55617464/28296770
func setupGlobalShortcuts() -> CFMachPort? {
// TODO: store in UserSettings if it is the first time the user is opening the app
// if it is, use CGRequestListenEventAccess, otherwise, just check with Preflight
let keyDownEventMask = CGEventMask(1 << CGEventType.keyDown.rawValue)
pin_project! {
pub struct BlockStream<R> {
#[pin]
reader: R,
buf: BytesMut,
}
}
impl<R: AsyncRead> Stream for BlockStream<R> {
type Item = io::Result<BytesMut>;
@jmg-duarte
jmg-duarte / colorset_to_accent.py
Created March 9, 2024 14:30
Extract a black/white accent for a .colorset/Contents.json color
import json
from typing import Any, Tuple
type RGB = Tuple[int, int, int]
type RGBA = Tuple[int, int, int, int]
def rgba_to_rgb(foreground: RGBA, background: RGB) -> RGB:
(fg_r, fg_g, fg_b, fg_a) = foreground
(bg_r, bg_g, bg_b) = background
@jmg-duarte
jmg-duarte / nhk.sh
Created October 27, 2023 16:30
NHK Episode Downloader
# Huge kudos to everyone working on yt-dlp, that's the heavylifting part
#
# The link points to Japanology+ but it should work with other series,
# maybe you'll need some adjustments to the jq query though
curl https://nwapi.nhk.jp/nhkworld/vodesdlist/v7b/program/japanologyplus/en/all/all.json |
jq -r ".data.episodes[].url" |
sed "s|^|https://www3.nhk.or.jp|" |
xargs -n 1 -P 2 yt-dlp
-- vim-plug
local Plug = vim.fn['plug#']
vim.call('plug#begin', '~/.config/nvim/plugged')
-- plenary provides utility functions for other plugins
-- think of it as a neovim plugin standard library
Plug('nvim-lua/plenary.nvim')
-- fuzzy finder file browser
Plug('nvim-telescope/telescope.nvim')
@jmg-duarte
jmg-duarte / parse_quote_dbg.rs
Last active May 6, 2023 19:10
Yandros parse_quote! debug
// Credits: Yandros#4299
macro_rules! parse_quote {(
$($code:tt)*
) => ({
eprintln!("[{}:{}:{}] parse_quote! {{ {} }}", file!(), line!(), column!(), quote!( $($code)* ));
::syn::parse_quote!( $($code)* )
})}
macro_rules! parse_quote {(

Keybase proof

I hereby claim:

  • I am jmg-duarte on github.
  • I am jmgduarte (https://keybase.io/jmgduarte) on keybase.
  • I have a public key ASCzSL2zUTqYGDlKA8Pe2l-tQn58IYUaOE6ni1WJZVUIhQo

To claim this, I am signing this object:

@jmg-duarte
jmg-duarte / starship.toml
Last active June 14, 2023 13:07
starship.toml
# add_newline = false
format="""\
$directory\
$package\
$git_branch\
$line_break\
$hostname\
$character\
"""
font_family Jetbrains Mono
bold_font Jetbrains Mono Bold
italic_font Jetbrains Mono Italic
bold_italic_font Jetbrains Mono Medium Italic
font_size 9.0
window_padding_width 10
initial_window_height 1280