Skip to content

Instantly share code, notes, and snippets.

@tera3939
tera3939 / setting.json
Created December 11, 2017 03:33
Visual Studio Codeの設定っぽい
//-------- Rust extension configuration --------
// The mode in which the extension will function
"rust.mode": "rls",
// Specifies path to Racer binary if it's not in PATH
"rust.racerPath": "C:\\Users\\tera\\.cargo\\bin\\racer.exe",
// Specifies path to Rustfmt binary if it's not in PATH
"rust.rustfmtPath": "C:\\Users\\tera\\.cargo\\bin\\rustfmt.exe",
@tera3939
tera3939 / word_count.py
Created December 8, 2017 03:31
https://paiza.jp/learning/word-count を一行でウェイってする奴
[print(*t) for terms, used in zip([input().split()], [set()]) for t in map(lambda x: (x, terms.count(x)), terms) if t not in used and (used.add(t) or True)]
@tera3939
tera3939 / main.py
Last active August 3, 2017 13:36
分割統治法で階乗計算
# -*- encoding: utf-8 -*-
def each_slice_2(f, iterator):
a = iterator.__iter__()
for i in a:
try:
j = a.__next__()
except:
j = 0
yield f(i, j)
@tera3939
tera3939 / main.rs
Created June 19, 2017 13:56
ぴゅあぴゅあList
#![feature(box_syntax)]
use std::rc::Rc;
#[derive(Debug)]
enum List<T: Clone> {
Empty,
Exist(Rc<Box<Node<T>>>),
}
def _to_snake_case(word):
final = ''
for item in word:
if item.isupper():
final += "_" + item.lower()
else:
final += item
if final[0] == "_":
final = final[1:]
return final
@tera3939
tera3939 / __init__.py
Created May 28, 2017 12:21
Pythonのimport文をホックするやつ
import sys
from . import music_importer
sys.meta_path.append(music_importer.MusicImporter)
# このモジュールでimport sysされているため、必ずsys.modulesにsysはある
sys.modules['sys'] = sys
@tera3939
tera3939 / hoge.rs
Created May 19, 2017 04:23
迷走のはて
// 構造体の初期化をマクロでウェイッってしたかった
#[derive(Debug)]
enum DataSize {
DWard,
Ward,
Byte
}
fn hoge(data: &[u8], offset: usize, data_size: DataSize) -> (&[u8], usize) {
Compiling twefi v0.1.0 (file:///home/tera/repos/twefi)
Running `rustc --crate-name twefi src/lib.rs --crate-type dylib --emit=dep-info,link -C debuginfo=2 -C metadata=2a5d295b588c4ecc --out-dir /home/tera/repos/twefi/target/x86_64-pc-windows-gnu/debug/deps --target x86_64-pc-windows-gnu -C linker=/usr/bin/x86_64-w64-mingw32-gcc -L dependency=/home/tera/repos/twefi/target/x86_64-pc-windows-gnu/debug/deps -L dependency=/home/tera/repos/twefi/target/debug/deps -C link-arg=-Wl,--gc-sections`
error: language item required, but not found: `panic_fmt`
error: language item required, but not found: `eh_personality`
error: language item required, but not found: `eh_unwind_resume`
error: aborting due to 3 previous errors
@tera3939
tera3939 / bin2wav.py
Created February 5, 2017 07:42
バイナリをwavに変換するやつ
# -*-encoding:utf-8-*-
import sys
import wave
def bin2wav(filedata, filename, channels=2, sampwidth=2, framerate=14400, nframe=0, comptype='NONE', compname='not compressed'):
w = wave.Wave_write(filename)
p = (channels, sampwidth, framerate, nframe, comptype, compname)
w.setparams(p)
@tera3939
tera3939 / main.rs
Created February 4, 2017 14:23
パーサーコンビネータになりたかったもの
use std::ascii::AsciiExt;
use std::cell::{Cell, RefCell};
use std::error::Error;
use std::fmt;
#[derive(Debug)]
enum ParseError {
Parse,
}