This file contains 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
#[cfg(target_os = "windows")] | |
extern { | |
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=msvc-170 | |
// https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa298581(v=vs.60) | |
fn _setmode(fd: std::os::raw::c_int, mode: std::os::raw::c_int) -> std::os::raw::c_int; | |
// https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/wwfcfxas(v=vs.100) | |
fn _get_errno(p_value: *mut std::os::raw::c_int) -> std::os::raw::c_int; | |
} | |
#[cfg(target_os = "windows")] |
This file contains 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 aes::cipher::block_padding::Pkcs7; | |
use aes::cipher::{KeyIvInit, BlockEncryptMut, BlockDecryptMut}; | |
use rand::RngCore; | |
type Aes256CbcEnc = cbc::Encryptor<aes::Aes256>; | |
type Aes256CbcDec = cbc::Decryptor<aes::Aes256>; | |
const AES256_SECRET_SIZE: usize = 32; | |
const AES256_BLOCK_SIZE: usize = 16; |
This file contains 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 | |
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes | |
from cryptography.hazmat.primitives import padding | |
# https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption/ | |
# https://cryptography.io/en/latest/hazmat/primitives/padding/#cryptography.hazmat.primitives.padding.PKCS7 | |
class AES256: | |
KEY_SIZE = 32 | |
BLOCK_SIZE = 16 |
This file contains 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 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 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 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 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 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 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| { |
NewerOlder