Skip to content

Instantly share code, notes, and snippets.

View lifthrasiir's full-sized avatar

Kang Seonghoon lifthrasiir

View GitHub Profile
@lifthrasiir
lifthrasiir / pub-use-and-mod.md
Created March 11, 2014 06:29
Pub, use and mod

There are some intertwined concepts in Rust module system:

  • Visibility
  • Physical file path
  • Logical module path

One should note that these three concepts are completely independent to others. While rustc automatically infers the physical file path from the logical module path, it is just for the convenience and you can always override this behavior with #[path] attribute.

@lifthrasiir
lifthrasiir / read.md
Last active August 29, 2015 13:57
read.rs design

What the hell is this

Read is intended to be a counterpart to the standard std::fmt library: it parses values out of the string instead of formatting the string out of values. It (mostly) shares the same formatting syntax as std::fmt.

Warning: This is a library design and yet to be implemented.

Read trait

@lifthrasiir
lifthrasiir / README.md
Last active March 5, 2020 12:02
GCJ 2014 QR submission

This is my submission to Google Code Jam 2014 Qualification Round, using Rust programming language. The full description of problems is available at Google.

I've solved all 4 problems over the course of 5 1/2 hours (2014-04-13T05:10+09:00 through T10:40+09:00), which were longer than I've expected (possibly because I was sleepy at that time), but I've got the full credit (90 out of 90) anyway, so I guess it was not so bad move.

I tried to write the idiomatic Rust as much as possible, but not always mostly due to the time constraints. In particular, all program shares same boilerplates for the general structure and I/O which I really don't like.

@lifthrasiir
lifthrasiir / update-rust
Created May 9, 2014 06:23
A script for downloading and extracting the official Rust nightly
#!/bin/bash
# A script for downloading and extracting the official Rust nightly
# Written by Kang Seonghoon, put in the public domain. No warranty.
#
# LOCALRUST should be set to a directory to hold all Rust-related files
# including `bin`, `lib` etc. Since the script tries to erase all files
# and extract new files, LOCALRUST should be dedicated to this purpose only
# (i.e. do not set it to `/usr/local` or similar, you've been warned).
#
# The script will create `update-rust.last` file to track the most recent update.
@lifthrasiir
lifthrasiir / gist:db14ec3ba0e519f03e10
Created May 14, 2014 17:04
Rust-encoding benchmark as of 59a6fa2dee46f403e1e8be3ce2421ffc488184f2 (2014-05-15)
running 33 tests
test codec::japanese::eucjp_tests::bench_decode_short_text ... bench: 5431 ns/iter (+/- 59) = 111 MB/s
test codec::japanese::eucjp_tests::bench_encode_short_text ... bench: 7007 ns/iter (+/- 18) = 128 MB/s
test codec::japanese::iso2022jp_tests::bench_decode_short_text ... bench: 7380 ns/iter (+/- 41) = 86 MB/s
test codec::japanese::iso2022jp_tests::bench_encode_short_text ... bench: 9415 ns/iter (+/- 24) = 95 MB/s
test codec::japanese::windows31j_tests::bench_decode_short_text ... bench: 6588 ns/iter (+/- 14) = 91 MB/s
test codec::japanese::windows31j_tests::bench_encode_short_text ... bench: 8354 ns/iter (+/- 26) = 107 MB/s
test codec::korean::windows949_tests::bench_decode_short_text ... bench: 6482 ns/iter (+/- 82) = 98 MB/s
test codec::korean::windows949_tests::bench_encode_short_text ... bench: 8592 ns/iter (+/- 13
@lifthrasiir
lifthrasiir / no-box.md
Last active June 27, 2017 08:46
Idiomatic Rust: Yes I'm really trying to write something similar

No Box<T>

tl;dr: Avoid Box<T> in general.

Actually, this rule is so important that the Rust Pointer Guide explicitly says the same. Therefore without a further ado, you should avoid Box<T> except for these three cases:

  1. When you absolutely need a trait object (Box<Trait>). But review carefully to see if it is indeed absolutely needed; you may try to generalize things too far, for example.

  2. When you have a recursive data structure. This may be mandatory when you have an inherently recursive data (e.g. scene graph), but it may also be a sign of the premature optimization. Again, review carefully to see if you need to write a separate data structure yourself, and use the collection crate if possible.

@lifthrasiir
lifthrasiir / store.md
Last active August 29, 2015 14:02
Achimnol's Minecraft Realm Store Guide (As of 2014-06-23)
  • E = Emerald
  • Some redundant dummy entries have been omitted

Building Blocks

  • 32 Cobblestone (1/2 stack) → 1E
  • 1E → 8 End Stone
  • 1E → 12 Hardened Clay
    • As opposed to: 48 Clay + fuel → 12 Hardened Clay
  • 1E → 8 Packed Ice
@lifthrasiir
lifthrasiir / sonorous-skin-ko.md
Last active August 29, 2015 14:03
Sonorous 스킨 시스템 매뉴얼 비스무리한 거

Sonorous 스킨 시스템

어떻게 작동하는가

Sonorous에서 변경 가능한 내용은 미리 지정된 훅(hook)을 통해 그려진다. 훅은 크게 블록 훅(block hook)과 스칼라 훅(scalar hook)으로 나뉜다. 블록 훅은 특정한 요소를 미리 지정된 조건에 따라 0번 이상 그리는데, 이를테면 특정 조건이 만족될 때만 요소가 보이거나(예: BGA가 있으면 BGA를 보여 준다), 조건에 따라 다른 요소를 보여 주거나(예: 제목이 있으면 제목을 보여 주고 없으면 "제목 없음"이라고 표시한다), 임의 길이의 목록을 보여 주거나(예: 곡 목록) 하는 용도로 쓰인다. 스칼라 훅은 문자열(예: 곡 제목)이나 숫자(예: 곡 레벨), 텍스쳐(예: 배너 이미지) 등을 반환한다. 일반적으로 블록 훅 안에서는 안에서만 의미가 있는 다른 블록 훅이나 스칼라 훅을 쓸 수 있게 된다.

Sonorous 스킨 시스템은 화면에 무언가를 그릴 때마다 클리핑 사각형(clipping rectangle)이라는 걸 관리한다. 이건 두 가지 용도로 쓰이는데 일단 상대 위치를 절대 위치로 바꾸는데 사용한다. 어느 요소가 사각형으로 구성되어 있는데 그 안에 다른 요소가 있으면 둘 다 절대 위치로 쓸 수도 있지만 바깥 요소에 해당하는 클리핑 사각형을 설정해서 다른 요소를 그 사각형을 기준으로 좌표를 지정하면 편리할 수도 있다. 또한 만약 클리핑 사각형이 충분히 작아져서 아무리 그리려고 해도 아무 것도 그릴 수 없게 된다면 더 그릴 게 남아 있어도 계속 진행할 이유가 없으므로 거기서 멈추는 역할도 한다. 둘을 종합하면 목록 같은 걸 유연하게 표시하는 용도로 쓰일 수 있다.

이제 이런 화면을 만들고 싶다고 하자:

@lifthrasiir
lifthrasiir / c11-to-rust.md
Last active September 16, 2021 13:30
C11 standard library to Rust standard library (as of 2014-07-19 nightly)

As a response to Issue #15753. Not yet complete.

Some notes:

  • All Rust translations assume the crate root (so the reference to std is freely available). The use of any other crates is noted.
  • Every string or vector argument is assumed to be a slice (&str or &[T]). Otherwise you need to convert String or Vec<T> to a slice with .as_slice() method.

<assert.h>

  • assert(cond): assert!(cond) macro. Note that it's always enabled; if you need to selectively disable the assertions, use debug_assert!(cond) macro.
@lifthrasiir
lifthrasiir / .gitignore
Last active August 29, 2015 14:04
Rust-consttime (An obsoleted proof of concept; DO NOT USE THIS!)
target
doc