Skip to content

Instantly share code, notes, and snippets.

View gyu-don's full-sized avatar

Takumi Kato gyu-don

View GitHub Profile
#![allow(unused_macros, unused_imports, dead_code)]
use std::io::*;
use std::collections::*;
fn read_line() -> String {
let mut s = String::new();
stdin().read_line(&mut s).unwrap();
s
}
@gyu-don
gyu-don / let_from_str.rs
Created August 15, 2017 23:35
Rust macro for making variable from parsed string.
macro_rules! let_from_str {
($($a:ident : $t:ty),+ = $s:expr) => {
$(let $a: $t;)+
{
let mut _it = $s.split_whitespace();
$($a = _it.next().unwrap().parse().unwrap();)+
assert!(_it.next().is_none());
}
};
}
@gyu-don
gyu-don / let_from_iter.rs
Created August 15, 2017 23:16
Rust macro for making variables from a iterator.
macro_rules! let_from_iter {
($($a:ident),+ = $it:expr) => {
$(let $a;)+
{
let mut _it = $it.into_iter();
$($a = _it.next().unwrap();)+
assert!(_it.next().is_none());
}
};
}
@gyu-don
gyu-don / print_var.rs
Created August 15, 2017 22:59
Rust macro for print variable (or value)
macro_rules! print_var_fmt {
($e:expr) => {
concat!(stringify!($e), ":\t{}")
};
($e:expr, $($es: expr),+) => {
concat!(print_var_fmt!($e), ",\t", print_var_fmt!($($es),+))
};
}
macro_rules! print_var {
@gyu-don
gyu-don / config
Created March 11, 2017 07:35
i3 config file
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
@gyu-don
gyu-don / dolphin_gesture.khotkeys
Created October 26, 2016 16:37
KDE Dolphin mousegesture
[Data]
DataCount=1
[Data_1]
Comment=Dolphin の基本的なジェスチャーです。(マウスジェスチャーに使用するボタンは「全体設定」で変更できます)
DataCount=12
Enabled=true
Name=Dolphin ジェスチャー
SystemGroup=0
Type=ACTION_DATA_GROUP
@gyu-don
gyu-don / fizzbuzz_oneline.py
Last active March 23, 2023 20:23
maybe, shortest fizzbuzz of python3
for i in range(100):print(i%3//2*"Fizz"+i%5//4*"Buzz"or-~i)
@gyu-don
gyu-don / dotdict.py
Last active July 6, 2016 13:33
tips for python
class dotdict(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
"""descriptions:
Like a JavaScript, get dictionary item via attribute.
d = dotdict()
d.a = 1
print(d.a) # ==> 1
@gyu-don
gyu-don / wp_hops.py
Created June 26, 2016 05:11
wp_hops Part-2
import sys
import getpass
import mysql.connector
class WordNotFoundError(Exception):
def __init__(self, word):
self.word = word
def __str__(self):
return self.word + " was not found."
@gyu-don
gyu-don / wp_hops.py
Created June 25, 2016 14:03
wp_hops Part-1
import sys
import getpass
import mysql.connector
class WordNotFoundError(Exception):
def __init__(self, word):
self.word = word
def __str__(self):
return self.word + " was not found."