This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import os | |
| import sys | |
| DIR_STACK = [] | |
| def pushd(path: str): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "io" | |
| "net/http" | |
| "time" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use lmdb::{Cursor, Transaction}; | |
| fn test_lmdb_dup_sort_update_in_place() -> anyhow::Result<()> { | |
| let db_dir = "lmdb-dir"; | |
| if let Err(err) = std::fs::remove_dir_all(db_dir) { | |
| if err.kind() != std::io::ErrorKind::NotFound { | |
| return Err(err.try_into()?); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use lmdb::{Cursor, Transaction}; | |
| fn test_lmdb_dup_sort_update_in_place() -> anyhow::Result<()> { | |
| let db_dir = "lmdb-dir"; | |
| if let Err(err) = std::fs::remove_dir_all(db_dir) { | |
| if err.kind() != std::io::ErrorKind::NotFound { | |
| return Err(err.try_into()?); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use lmdb::{Cursor, Transaction}; | |
| fn test_lmdb_dup_sort_update_in_place() -> anyhow::Result<()> { | |
| let db_dir = "lmdb-dir"; | |
| if let Err(err) = std::fs::remove_dir_all(db_dir) { | |
| if err.kind() != std::io::ErrorKind::NotFound { | |
| return Err(err.try_into()?); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Taken from with modifications | |
| // https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/#windows-server-code | |
| #undef UNICODE | |
| #include <winsock2.h> | |
| #include <windows.h> | |
| #include <ws2tcpip.h> | |
| #include <afunix.h> | |
| #include <stdlib.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn mean(data: &[u32]) -> f64 { | |
| let sum = data.iter().sum::<u32>() as f64; | |
| let count = data.len(); | |
| sum / count as f64 | |
| } | |
| fn std_deviation(data: &[u32]) -> f64 { | |
| if data.len() != 0 { | |
| let data_mean = mean(data); | |
| let variance = data.iter().map(|v| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::os::windows::fs::MetadataExt; | |
| // Nanoseconds between [Jan 1 1601, Jan 1 1970] | |
| const UNIX_EPOCH_OFFSET: u64 = 0x019d_b1de_d53e_8000; | |
| // Panic if file_time is below Jan 1 1970 | |
| fn filetime_to_unix_ns(file_time: u64) -> u64 { | |
| (file_time - UNIX_EPOCH_OFFSET) * 100 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const MAX_PATH_LEN: usize = 2048; | |
| #[allow(overflowing_literals)] | |
| const ERR_MOD_NOT_FOUND: windows::core::HRESULT = windows::core::HRESULT(0x8007007Ei32); | |
| pub fn win_sh_get_localized_name(path: &str) -> anyhow::Result<String> { | |
| let path_hstr = windows::core::HSTRING::from(path); | |
| let mut res_path = Vec::with_capacity(MAX_PATH_LEN); | |
| unsafe { res_path.set_len(res_path.capacity()); } | |
| let mut res_id = 0i32; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const WTS_CONNECT_STATE_ACTIVE: i32 = 0; | |
| // https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/ne-wtsapi32-wts_connectstate_class#syntax | |
| fn wts_state_to_string(state: windows::Win32::System::RemoteDesktop::WTS_CONNECTSTATE_CLASS) -> String { | |
| match state.0 { | |
| 0 => "Active".to_string(), | |
| 1 => "Connected".to_string(), | |
| 2 => "ConnectQuery".to_string(), | |
| 3 => "Shadow".to_string(), | |
| 4 => "Disconnected".to_string(), |