Skip to content

Instantly share code, notes, and snippets.

@cfsamson
cfsamson / fantoccini_downloader.rs
Last active February 21, 2023 23:48
Fantocini file downloader - when you can't manually issua a GET request
// Cargo.toml
//
// [dependencies]
// serde_json = "1.0.61"
// notify = "4.0.15"
// anyhow = "1.0.38"
// fantoccini = "0.17.1"
// tokio = {version="1.1.1", features= ["full"]}
// log = "0.4.14"
// env_logger = "0.8.2"
@cfsamson
cfsamson / lexer.rs
Last active March 10, 2024 21:33
Code for a simple rust lexer for use in a simple example to rewrite code
use core::{num, slice};
use std::{io::Lines, string};
const STRING_BORDER: char = '"';
#[derive(Debug)]
enum NonTerminal {
ArgumentOpen,
ArgumentClose,
BlockOpen,
use core::fmt;
use fmt::Display;
use serde::{
ser::{Error, SerializeMap, SerializeSeq},
serde_if_integer128, Deserialize, Serialize, Serializer,
};
fn main() {
#[derive(Serialize, Deserialize)]
struct Demo {
@cfsamson
cfsamson / tic_tac_toe.rs
Created April 26, 2020 14:33
Tic-tac-toe Rust
use rand;
use std::{
fmt,
io::{stdin, Read},
};
fn main() {
run();
}
@cfsamson
cfsamson / generators_v1.rs
Created January 28, 2020 17:20
Futures, generators and pin
use std::pin::Pin;
pub fn test1() {
let mut test1 = Test::new("test1");
test1.init();
let mut test1_pin = Pin::new(&mut test1);
let mut test2 = Test::new("test2");
test2.init();
let mut test2_pin = Pin::new(&mut test2);
use std::thread;
use std::sync::atomic::{AtomicBool, Ordering};
const LOCKED: AtomicBool = AtomicBool::new(false);
static mut COUNTER: usize = 0;
#[inline(always)]
pub fn test(inc: usize) {
while LOCKED.compare_and_swap(true, false, Ordering::Relaxed) {
}
@cfsamson
cfsamson / SetTimeDateAndUpdate.ps1
Created November 7, 2019 00:56 — forked from HauptJ/SetTimeDateAndUpdate.ps1
Powershell script to set date and time settings and update Windows
############################################################
# Powershell script to set date and time settings and update Windows
# Author: Joshua Haupt josh@hauptj.com Date: 22.12.2017
############################################################
@cfsamson
cfsamson / batch_insert_tiberius.rs
Last active November 2, 2019 12:01
How to insert more than 1000 rows on mssql server and how to efficiently update many rows
use tiberius::SqlConnection;
use futures::Future;
use futures_state_stream::StateStream;
use tokio_current_thread::block_on_all;
fn main() {
init();
create();
batch_insert();
struct StoreResult {
saved: String,
}
#[allow(unused_variables, non_upper_case_globals)]
const __IMPL_RESPONSE_FOR_StoreResult: () = {
extern crate tower_web as __tw;
impl __tw::response::Response for StoreResult {
type Buf = <Self::Body as __tw::util::BufStream>::Item;
type Body = __tw::error::Map<__tw::codegen::bytes::Bytes>;
@cfsamson
cfsamson / rust_easier_optional_string_field_concat.rs
Created September 13, 2019 22:01
A macro to ease the concatination of meny optional string fields like in large structs representing json objects that have many possibly empty fields
use std::fmt;
macro_rules! txt_concat {
($($model: expr), *) => {{
let mut s = String::new();
$(
if let Some(t) = $model {
s.push_str(&t);
s.push(' ');