Skip to content

Instantly share code, notes, and snippets.

fn ui<B: Backend>(f: &mut Frame<B>, app: &App) {
let size = f.size();
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(5)
.constraints(
[
Constraint::Percentage(25),
Constraint::Percentage(25),
Constraint::Percentage(25),
@sophacles
sophacles / Cargo.toml
Last active April 5, 2023 13:12
block splitting
[package]
name = "nested_blocks"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ratatui = "0.20.1"
crossterm = "0.23.2"
import csv
from calendar import monthrange
def get_n_days(year, month):
return monthrange(year, month)[1]
def due_month(year, month):
due_month = ((month + 6) % 12)
if due_month == 0: due_month = 12
due_year = year + ((month + 6) // 12)
@sophacles
sophacles / forkpty_wrapper.py
Last active September 13, 2015 16:19
a posix forkpty implementation for gevent - works with pexpect nicely
# Make a forkpty wrapper that works nicely with gevent.
# This only wraps the process properly, the same way gevent.os.fork() does,
# and doesn't do anything special for dealing with the pty file descriptor.
#
# This was originally intended to work with pexpect, and does so nicely, since the
# head version of pexpect uses select.select and time.sleep in many places, effectively
# "geventifying" the expect interactions.
#
# Other things using forkpty and doing reads and writes via the pty will need to
# take a look at doing proper gevent wrapping of operations on the fd for now.
@sophacles
sophacles / cli
Last active August 29, 2015 14:19
# Now you can do this from the command line:
$ commandname --list
--list
Available tasks:
foo
@sophacles
sophacles / gist:c17ce33a14d582dfa268
Created August 20, 2014 17:03
Functions for making entry points with invoke
import invoke
import invoke.cli
from invoke import run, ctask as task, Collection
import sys
def redo_args(coll, baseargs=[]):
import our_tasks
root = our_tasks.__path__[0]
print "root is:", root
args = sys.argv[1:]
void blockwrite(struct SR *sr, unsigned long long data, int bits) {
if (!SR_WRITEABLE(sr, bits)) {
wait = (bits + sr->pos) - 32;
LED_OUT &= ~LED1;
}
while (wait) {
//loop till something else makes wait go to 0
}
if (1) LED_OUT |= LED1;
class N(object): # analogous to a Task class
def __init__(self, func):
self.run = func
self.a = ":("
self.b = ":("
self.c = ":("
self.d = ":("
def __call__(self, *args, **kw):
print 'N WRAPPED a:', self.a, 'b:', self.b, 'c:', self.c, 'd:', self.d