Skip to content

Instantly share code, notes, and snippets.

@se1983
se1983 / main.rs
Created March 17, 2024 13:45
epoll in rust using nix
use clap::Parser;
use nix::fcntl::{open, OFlag};
use nix::sys::epoll::{epoll_create, epoll_ctl, epoll_wait, EpollEvent, EpollFlags, EpollOp};
use nix::sys::stat::Mode;
use std::collections::HashMap;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
#[clap(value_delimiter = ' ', num_args = 1..)]
@se1983
se1983 / main.rs
Created March 16, 2024 12:43
Signal driven I/O
use nix::libc::{F_SETOWN, STDIN_FILENO};
use nix::sys::signal::{SigSet, Signal, SigHandler, SigAction, SaFlags, sigaction};
use nix::unistd::{getpid, read};
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use std::time::Duration;
use nix::fcntl::fcntl;
static SIGNAL_RECEIVED: AtomicBool = AtomicBool::new(false);
@se1983
se1983 / main.rs
Last active December 30, 2023 13:30
script in rust to rearrange all files in one directory into a folder structure /YYYY/MM/
use chrono::{Datelike, NaiveDate, NaiveDateTime};
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};
use std::string::ToString;
use chrono::prelude::{DateTime, Utc};
use console::{style, Emoji};
use regex::Regex;
use walkdir::WalkDir;
@se1983
se1983 / main.rs
Last active March 20, 2024 10:35
#![no_std]
#![no_main]
use arduino_hal::hal::port::{PD3, PD5, PD6};
use arduino_hal::pac::TC0;
use arduino_hal::port::mode::{Analog, Input, Output, PwmOutput};
use arduino_hal::port::{mode, Pin, PinOps};
use arduino_hal::prelude::*;
use arduino_hal::simple_pwm::{IntoPwmPin, PwmPinOps, Timer0Pwm, Timer2Pwm};
use arduino_hal::{DefaultClock, Peripherals, Pins, Usart};
import time
import requests
""" Develop an asynchronous REST API with any Python Framework you like. """
BONUS_POINTS = False
def test_api():
#!/bin/bash
# compiles python3.10 on centos 7
# sebsch 2022-02-02
yum groupinstall development -y
yum install wget zlib-devel gcc openssl-devel bzip2-devel libffi-devel xz-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel expat-devel -y
cd ~
echo "INSTALL python3.10"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello API!</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css">
<script src="https://unpkg.com/vue@next"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
const app = Vue.createApp({
data: function () {
return {
output: null
}
}
})
app.component('poll-button', {
@se1983
se1983 / index.html
Created June 16, 2021 17:53
some random vue stuff
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello API!</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
@se1983
se1983 / capture_linux_processes.rs
Last active April 17, 2021 21:19
Use rust tokio to capture stdout of processes using proc/{pid}/fd/1
extern crate tokio;
use std::fs;
use std::path::{Path, PathBuf};
use std::os::linux::fs::MetadataExt;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
use tokio::time::{sleep, Duration};
use log::{info, LevelFilter};
use simple_logger::SimpleLogger;