Skip to content

Instantly share code, notes, and snippets.

View YoshiTheChinchilla's full-sized avatar
:octocat:
On GitHub

Yoshi YoshiTheChinchilla

:octocat:
On GitHub
  • Worldwide
View GitHub Profile
/// "2$4$8$16"
/// ↓
/// "$"を"#"に置換
/// ↓
/// "2#4#8#16"
/// ↓
/// "#"を区切り文字に配列へ分割
/// その要素数を表示
/// ↓
fn to_rgb(r: usize, g: usize, b: usize) -> String {
format!("#{:02X}{:02X}{:02X}", r, g, b)
}
fn main() {
// let mut args = std::env::args();
// args.skip().next().unwrap(), args.next().unwrap(), args.next().unwrap()
assert_eq!(to_rgb(200, 15, 1), "#C80F01");
}
@YoshiTheChinchilla
YoshiTheChinchilla / match-pattern-benchmark.js
Created January 29, 2021 07:53
Benchmarking RegExp and String procedure in JavaScript https://github.com/bestiejs/benchmark.js
// $ npm i --save benchmark microtime
const Benchmark = require('benchmark')
const suite = new Benchmark.Suite
const str = 'E0123'
const compiledRegex = new RegExp(/E\d{4}/)
suite
.add('RegExp#match', function() {
const matched = str.match(/E\d+/)

問題1. 選択肢の中からRubyの予約語ではないものを2つ選択してください。

  • A. super
  • B. begin
  • C. try
  • D. goto
解答

C,D

@YoshiTheChinchilla
YoshiTheChinchilla / zero_array_of.rs
Created January 18, 2021 16:26
Zero array with generics
#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
use std::mem::size_of;
pub fn zero_array_of<T>() -> [u8; size_of::<T>()] {
[0u8; { size_of::<T>() }]
}
#[cfg(test)]
[
{"year": 1983, "slogan": "これまでで一番強くかつ攻撃的な味"},
{"year": 1985, "slogan": "近年にない上物"},
{"year": 1992, "slogan": "過去2年のものよりフルーティーで、軽い"},
{"year": 1995, "slogan": "ここ数年で一番出来が良い"},
{"year": 1996, "slogan": "10年に1度の逸品"},
{"year": 1997, "slogan": "まろやかで濃厚。近年まれにみるワインの出来で過去10年間でトップクラス"},
{"year": 1998, "slogan": "例年のようにおいしく、フレッシュな口当たり"},
{"year": 1999, "slogan": "1000年代最後の新酒ワインは近年にない出来"},
{"year": 2000, "slogan": "今世紀最後の新酒ワインは色鮮やか、甘みがある味"},
@YoshiTheChinchilla
YoshiTheChinchilla / AutoHeight.vue
Created November 27, 2020 10:22
simple implementation in Vue.js of auto adjusting height for YouTube iFrame
<template>
<div class="iframe-container">
<iframe class="iframe-content" src="https://www.youtube.com/embed/g06zI68Blzk"></iframe>
</div>
</template>
<script>
export default {}
</script>
@YoshiTheChinchilla
YoshiTheChinchilla / main.rs
Created October 13, 2020 05:24
nom the parser performance comparison between spaces and tabs https://github.com/Geal/nom
use std::time::Instant;
use nom::character::complete::*;
use nom::error::ParseError;
use nom::{AsChar, InputIter, InputTakeAtPosition, Slice};
fn parse_spaces<T, E: ParseError<T>>(mut input: T) -> i32
where
T: InputTakeAtPosition + InputIter + Slice<std::ops::RangeFrom<usize>>,
<T as InputTakeAtPosition>::Item: AsChar + Clone,
@YoshiTheChinchilla
YoshiTheChinchilla / union_find.rs
Created September 7, 2020 12:06
The simplest Union-find written in Rust. Edit this code with your taste and use it.
struct UnionFind {
par: Vec<usize>,
rank: Vec<usize>,
}
impl UnionFind {
fn new(n: usize) -> UnionFind {
let mut par = Vec::with_capacity(n);
for i in 0..n {
par[i] = i;
@YoshiTheChinchilla
YoshiTheChinchilla / Cargo.toml
Last active January 14, 2021 05:24
A Kiyoshi Hikawa's Zundoko Bushi script written in Rust
[package]
name = "zundoko"
version = "0.1.0"
authors = ["Takashi Yoshimura"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "zundoko"