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
#[derive(Clone)] | |
struct RatioBuilder{ | |
n:i64, | |
a_name:Option<String>, | |
a_ratio:Option<i64>, | |
b_name:Option<String>, | |
b_ratio:Option<i64>, | |
} | |
impl RatioBuilder{ |
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
l=123;s=string.ascii_letters+string.digits;print(''.join(random.sample((s)*math.ceil(l/(len(s))),k=l))) |
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
// C版 | |
// Rust版で作成するMutex名と同じにすると、競合させられる。 | |
#include<windows.h> | |
#include<stdio.h> | |
int main() { | |
// 名前付きミューテックスを作り、確保する | |
CreateMutexA(NULL,0,"AAAAA_NAMED_MUTEX\0"); | |
if(GetLastError()==183){ | |
// すでに獲得済みのミューテックスの場合は183がGetLastErrorから返却される。 |
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
// 参考:https://qiita.com/Nossa/items/a93024e653ff939115c6 | |
trait Shape{ | |
fn area(&self)->f32; | |
fn whoami(&self)->String; | |
} | |
struct Triangle { | |
pub base:f32, | |
pub height:f32 | |
} |
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
extern crate crypto_hash; | |
extern crate ssdeep; | |
use crypto_hash::{Algorithm, hex_digest}; | |
extern crate levenshtein; | |
use levenshtein::levenshtein; | |
fn main() { | |
// ハッシュ化対象の文字列 | |
let hashes=&[b"give me hashsing!!",b"give you hashsing!",b"AAAAAAAAAAAAAAAAA!"]; | |
// 記録用のベクタ |
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::thread; | |
use std::time::Duration; | |
use std::sync::{Arc,Mutex}; | |
use std::ptr::NonNull; | |
// いんなー | |
// 32ビット整数値と、外部の配列へのポインタ(C-FFIとかでよくやるやつ) | |
struct Inner{ | |
num:u32, | |
u8ptr:SafeRawU8Ptr |
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
extern crate rand; | |
use rand::Rng; | |
fn main() { | |
let mut vec=(0x20..0x7f) | |
.filter_map(|n|std::char::from_u32(n as u32)) | |
.collect::<Vec<char>>(); | |
rand::thread_rng().shuffle(&mut vec); | |
vec.iter().for_each(|n|print!("{}",n)); | |
} |
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 main(){ | |
let n = (0..20).collect::<Vec<u32>>(); | |
let v = n.iter().filter(|n|(*n)%2==1).map(|n|n*2).collect::<Vec<u32>>(); | |
let fb = n.iter().map(fizzbuzz).collect::<Vec<String>>(); | |
println!("{:?}",v); | |
println!("{:?}",fb); | |
//もっとスマートに書くと | |
println!("{:?}",(0..20).filter(|n|(*n)%2==1).map(|n| n * n).collect::<Vec<u32>>()); |
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::io::stdin; | |
use std::io::Write; | |
use std::str::FromStr; | |
use std::io::Read; | |
use std::fmt::{Debug, Display}; | |
use std::error::Error; | |
#[derive(Debug)] | |
struct drink<'a>{ | |
price:u32, |
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
#[derive(Debug)] | |
struct FizzBuzzData{ | |
num:u32, | |
id:&'static str | |
} | |
#[derive(Debug)] | |
struct FizzBuzzN{ | |
data:Vec<FizzBuzzData>, | |
} |