Skip to content

Instantly share code, notes, and snippets.

@sigmaSd
sigmaSd / .rs
Created November 1, 2020 09:59
channel
use super::Event;
use super::{stringify_sendall_errors, Application, NetMessage};
use crate::state::{ApplicationState, TermchatMessageType};
use crate::ui;
use crate::util::{termchat_message, Result};
use crossterm::event::{Event as TermEvent, KeyCode, KeyEvent, KeyModifiers};
impl Application {
pub fn parse_input(&mut self, input: &str, state: &mut ApplicationState) -> Result<()> {
const SEND_COMMAND: &str = "?send";
@sigmaSd
sigmaSd / showkey.rs
Last active November 4, 2020 16:21
[dependencies] ctrlc = "3.1.7" libc = "0.2.80" scopeguard = "1.1.0" termios = "0.3.3"
use std::io;
use std::io::prelude::*;
use std::os::unix::io::AsRawFd;
use termios::*;
const KDSKBMODE: u64 = 0x4B45;
fn main() {
if let Err(e) = try_main() {
eprintln!("Something happened: {}", e);
fn copy_region() -> Result<()> {
let region = std::process::Command::new("slurp").output()?;
let mut region = String::from_utf8(region.stdout)?;
region.pop(); // remove \n
std::process::Command::new("grim")
.args(&["-g", &region])
.arg(std::env::temp_dir().join("select.png"))
.spawn()?
.wait()?;
let mut lt = leptess::LepTess::new(None, "eng").unwrap();
struct UnlimitedPeekable<T, I: Iterator<Item = T>> {
iter: I,
read: Vec<T>,
}
impl<T, I: Iterator<Item = T>> UnlimitedPeekable<T, I> {
fn peek_n(&mut self, n: usize) -> Option<&T> {
// 1- indexed
if n <= self.read.len() {
self.read.get(n - 1)
} else {
pub fn read_until_bytes<R: std::io::BufRead + ?Sized>(
r: &mut R,
delim: &[u8],
buffer: &mut Vec<u8>,
) -> std::io::Result<usize> {
let mut read = 0;
let mut count = 0;
loop {
let (done, used) = {
let available = match r.fill_buf() {
@sigmaSd
sigmaSd / audio.rs
Created February 5, 2021 16:12
tcp audio
use fon::{stereo::Stereo32, Audio, Sink};
use pasts::{exec, wait};
use wavy::{Microphone, MicrophoneStream, Speakers, SpeakersSink};
const SAMPLE_RATE: f32 = 48_000.;
/// An event handled by the event loop.
enum Event<'a> {
/// Speaker is ready to play more audio.
Play(SpeakersSink<'a, Stereo32>),
@sigmaSd
sigmaSd / waydroid_binder.c
Created September 26, 2021 10:50
Allocate binder devices for waydroid
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
import puppeteer from "https://deno.land/x/[email protected]/mod.ts";
const cliRepl = Deno.run({
cmd: ["deno", "repl", "--unstable", "--inspect"],
});
const browser = await puppeteer.launch({ headless: false });
const page = (await browser.pages())[0];
await page.goto(
const $ = async (e: string) => {
await Deno.run({
cmd: ["sh", "-c", e],
}).status();
};
const MAKE = "make";
const PUBLIC_DIR = "public";
const OUT_DIR = "build";
@sigmaSd
sigmaSd / deno-show.ts
Last active March 25, 2022 10:46
Show deno scripts
const homeDir = () => {
switch (Deno.build.os) {
case "linux":
case "darwin":
return Deno.env.get("HOME");
case "windows":
return Deno.env.get("USERPROFILE");
}
};
const binaryPathFromName = (name: string) => `${homeDir()}/.deno/bin/${name}`;