Skip to content

Instantly share code, notes, and snippets.

View ruxo's full-sized avatar

Ruxo ruxo

  • Bangkok
View GitHub Profile
@ruxo
ruxo / AdaptiveExtension.fs
Last active April 28, 2023 23:20
(Broken) AsyncVal for UI async execution for FSharp.Data.Adaptive
[<AutoOpen>]
module Tirax.KMS.AdaptiveExtension
open System
open System.Runtime.CompilerServices
open FSharp.Data.Adaptive
[<Struct; IsReadOnly>]
type AsyncResult<'T> =
| Loading
function New-IsoFile
{
<# .Synopsis Creates a new .iso file .Description The New-IsoFile cmdlet creates a new .iso file containing content from chosen folders .Example New-IsoFile "c:\tools","c:Downloads\utils" This command creates a .iso file in $env:temp folder (default location) that contains c:\tools and c:\downloads\utils folders. The folders themselves are included at the root of the .iso image. .Example New-IsoFile -FromClipboard -Verbose Before running this command, select and copy (Ctrl-C) files/folders in Explorer first. .Example dir c:\WinPE | New-IsoFile -Path c:\temp\WinPE.iso -BootFile "${env:ProgramFiles(x86)}\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\efisys.bin" -Media DVDPLUSR -Title "WinPE" This command creates a bootable .iso file containing the content from c:\WinPE folder, but the folder itself isn't included. Boot file etfsboot.com can be found in Windows ADK. Refer to IMAPI_MEDIA_PHYSICAL_TYPE enumeration for possible media types: http://msdn.mi
[package]
name = "io_monad_guessing_game"
version = "0.1.0"
authors = ["Ruxo Zheng <[email protected]>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1"
@ruxo
ruxo / IO.cs
Last active February 5, 2023 08:27
Simple number guessing game with Aff/Eff..
using LanguageExt;
using LanguageExt.Common;
using NetConsole = System.Console;
// ReSharper disable InconsistentNaming
namespace TestConsole;
public delegate Either<Error, A> IO<in Env, A>(Env env);
interface ConsoleIO
@ruxo
ruxo / callback.rs
Last active January 15, 2023 06:44
An example of how to get an address of Rust's mutable closure in c_void pointer form in order to pass it to another handler. This should be useful for C library interface. The solution comes from https://stackoverflow.com/questions/38995701/how-do-i
use std::ffi::c_void;
// Create a wrapper structure to erase FnMut type from manipulation.
struct MutWrapper<'h> {
f: Box<dyn FnMut() -> () + 'h>,
}
impl<'h> MutWrapper<'h> {
fn new<F>(handler: F) -> Self where F: FnMut() + Send + 'h {
let f = Box::new(handler);
@ruxo
ruxo / main.rs
Last active December 29, 2022 22:40
Fixed address solution for Rust 1.66
use std::pin::Pin;
use std::ptr::null;
use std::sync::Arc;
#[derive(Clone)]
struct Test {
data: Pin<Arc<[u8; 8]>>,
reference: *const [u8; 8]
}
@ruxo
ruxo / Cargo.toml
Last active December 29, 2022 12:10
Rust for Windows Desktop app with Win32
[package]
name = "r4w"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[dependencies.windows]
@ruxo
ruxo / console.rs
Last active December 29, 2022 12:10
.NET-like Console functions
use std::io::{stdin, Error};
/// Write text output into STDOUT with string format supported. Like .NET `Console.Write()`
#[macro_export]
macro_rules! console_write {
($($args: tt)*) => {{
print!($($args)*);
std::io::Write::flush(&mut std::io::stdout())?;
}};
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace DesktopWallpaper
{
[StructLayout(LayoutKind.Sequential)]
var psi = new ProcessStartInfo
{
FileName = "mongo",
Arguments = $"{tlsSupport} --quiet --eval \"{query}\"",
CreateNoWindow = true,
RedirectStandardOutput = true
};
var procQuery = new Process
{