Skip to content

Instantly share code, notes, and snippets.

View qryxip's full-sized avatar

Ryo Yamashita qryxip

  • Japan
  • 19:21 (UTC +09:00)
View GitHub Profile
@qryxip
qryxip / S99.scala
Last active February 5, 2017 11:14
import scala.annotation.tailrec
object S99 {
object S99Lists {
@tailrec
def last[A](list: List[A]): A = list match {
case Nil => throw new IllegalArgumentException
case List(x) => x
#!cargo script
use std::fmt;
use std::fmt::{Display, Formatter};
use std::marker::PhantomData;
use std::ops::Add;
use std::cmp::{Eq, PartialEq};
struct Length<V, M> where M: Measure {
value: V,
@qryxip
qryxip / scan-stdin-once.rs
Last active September 8, 2018 11:43
Rustで競プロをやるための標準入力取得法
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
#[macro_use]
mod _input {
use std::fmt;
use std::io::{self, Read};
use std::str::{self, FromStr};
macro_rules! input {
#!/usr/bin/env run-cargo-script
//!```cargo
//![dependencies]
//!chrono = "0.3.0"
//!irc = "0.11.6"
//!lazy_static = "0.2.6"
//!regex = "0.2.1"
//!rustbox = "0.9.0"
//!```
@qryxip
qryxip / tester.rs
Created April 11, 2017 12:44
競プロ用のテスター(未完成)
#!/usr/bin/env run-cargo-script
//!```cargo
//![package]
//!authors = ["wariuni <wariuni@gmail.com>"]
//!name = tester
//!version = "0.1.0"
//!
//![dependencies]
//!toml = "0.3.2"
//!```
use std::borrow::Cow;
trait FromRefOpt<'a, T> {
fn from_ref_opt(option: Option<&'a T>) -> Self;
}
impl<'a, T: Clone + Default> FromRefOpt<'a, T> for Cow<'a, T> {
fn from_ref_opt(option: Option<&'a T>) -> Cow<'a, T> {
if let Some(x) = option {
macro_rules! array {
[$x: tt; $n: tt] => {array!(@go ($n, $x) -> ())};
(@end $x: tt) => {$x};
(@go (1, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@end [$($x,)* $($xs)*]) };
(@go (2, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@go (1, $($x), *) -> ($($x,)* $($xs)*))};
(@go (3, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@go (2, $($x), *) -> ($($x,)* $($xs)*))};
(@go (4, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@go (2, $($x,)* $($x), *) -> ($($xs)*))};
(@go (5, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@go (4, $($x), *) -> ($($x,)* $($xs)*))};
(@go (6, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@go (3, $($x,)* $($x), *) -> ($($xs)*))};
(@go (8, $($x: tt), *) -> ($($xs: tt)*)) => {array!(@go (4, $($x,)* $($x), *) -> ($($xs)*))};
#!/usr/bin/env run-cargo-script
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;
macro_rules! array {
[$x: tt; $n: tt] => {array!(@go ($n, $x) -> ())};
@qryxip
qryxip / usage_of_neon.rs
Last active May 1, 2017 04:55
https://github.com/neon-bindings/neon のドキュメントのサンプルコードが古いので
#[macro_use]
extern crate neon;
use neon::js::{JsInteger, JsString, JsUndefined, Object, Value};
use neon::js::class::Class;
use neon::vm::{FunctionCall, JsResult, Lock, This, Throw};
use std::ops::FnOnce;
use std::sync::{Arc, Mutex};
use std::thread;
#!/usr/bin/env run-cargo-script
//! ```cargo
//! [dependencies]
//! term = "0.4.6"
//! ```
extern crate term;
use std::env;
use std::ffi::OsString;