Skip to content

Instantly share code, notes, and snippets.

@se1983
se1983 / tokio_join.rs
Created July 5, 2020 08:14
Playing around with tokios join makro
use tokio::process;
use std::process::Stdio;
use std::time::Instant;
async fn sleep() -> Result<String, Box<dyn std::error::Error>> {
let ps = process::Command::new("sleep")
.stdout(Stdio::piped())
.arg("3")
.output().await?;
@se1983
se1983 / split_seperator_keep.rs
Created July 26, 2020 12:26
Split string at regex and keep seperator
use regex::Regex; // 1.1.8
fn split_keep<'a>(r: &Regex, text: &'a str) -> Vec<&'a str> {
let mut result = Vec::new();
let mut last = 0;
for (index, matched) in text.match_indices(r) {
if last != index {
result.push(&text[last..index]);
}
result.push(matched);
@se1983
se1983 / porter.rs
Created October 25, 2020 10:11
TCP Portscanner with threadpool in rust
use std::net::{TcpStream, IpAddr, SocketAddr};
use std::time::Duration;
use threadpool::ThreadPool;
use std::sync::mpsc::{channel, Sender};
use ipnet::Ipv4Net;
use std::thread::sleep;
static NETWORK: &str = "172.111.0.0/10";
static PORT: u16 = 80;
static POOLSIZE: usize = 7000;
@se1983
se1983 / tokio_mpsc.rs
Created December 31, 2020 10:14
most simple multi-producer-single-consumer in rust tokio
use tokio::sync::mpsc;
#[tokio::main]
pub async fn main() {
let (tx, mut rx) = mpsc::channel(32);
let tx2 = tx.clone();
tokio::spawn(async move {
tx.clone().send("sending from first handle").await;
});
@se1983
se1983 / deadmans_switch.py
Last active January 22, 2021 22:22
signal.SIGALARM watching the runtime of a procedure
import asyncio
import signal
from random import randint
class Timeout(Exception):
pass
def handle_timeout(signum, frame):
@se1983
se1983 / capture_linux_procs.py
Last active March 31, 2021 11:09
using async python to capture the outputs of all processes of the current user
import asyncio
import logging
import os
from dataclasses import dataclass
from typing import Iterable
from aiofile import AIOFile
logging.basicConfig(level=logging.INFO)
@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;
@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>
const app = Vue.createApp({
data: function () {
return {
output: null
}
}
})
app.component('poll-button', {
<!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>