Skip to content

Instantly share code, notes, and snippets.

View Bruce0203's full-sized avatar
🦀

Lee Jong-won Bruce0203

🦀
View GitHub Profile
@Bruce0203
Bruce0203 / const_transmute.rs
Created May 28, 2024 06:50
const_transmute.rs
/// A const reimplementation of the [`transmute`](core::mem::transmute) function,
/// avoiding problems when the compiler can't prove equal sizes.
///
/// # Safety
/// Treat this the same as [`transmute`](core::mem::transmute), or (preferably) don't use it at all.
#[inline(always)]
#[cfg_attr(not(feature = "internals"), doc(hidden))]
pub const unsafe fn const_transmute<A, B>(a: A) -> B {
if mem::size_of::<A>() != mem::size_of::<B>() {
panic!("Size mismatch for generic_array::const_transmute");
@Bruce0203
Bruce0203 / gist:1e5d60683525633de22615322d6c5cfb
Created May 22, 2024 16:47
PhantomData<T> derive Default impl issue
#[test]
fn compilation_success() {
use std::marker::PhantomData;
pub struct MyState<T> {
_marker: PhantomData<T>,
}
pub struct MyStruct;
@Bruce0203
Bruce0203 / init.vim
Last active February 8, 2024 06:59
init.vim
syntax enable
filetype plugin indent on
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'
Plug 'preservim/tagbar'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'vim-airline/vim-airline'
Plug 'frazrepo/vim-rainbow'
@Bruce0203
Bruce0203 / test.kt
Created July 19, 2023 11:01
korge prototype
```kotlin
import korlibs.time.*
import korlibs.korge.*
import korlibs.korge.scene.*
import korlibs.korge.tween.*
import korlibs.korge.view.*
import korlibs.image.color.*
import korlibs.image.format.*
import korlibs.io.file.std.*
import korlibs.korge.view.align.*
@Bruce0203
Bruce0203 / gist:10c74edb0effb92460ac65e634818d43
Created July 10, 2023 02:09
linguistics-chomsky google slide presentation
https://docs.google.com/presentation/d/1ezGsmADO2Zec4WgGFv1lOmJCQO7xZZKIFqi4qKDpOuA/edit#slide=id.gc6f73a04f_0_14
@Bruce0203
Bruce0203 / ang1
Last active June 3, 2023 11:32
mini game logic
miniGames:
MCdev:
spawnLocation:
world: games
x: -18.5
y: 41.0
z: 2.5
yaw: 0.0
pitch: 0.0
1,-1Location:
@Bruce0203
Bruce0203 / DoesHashMapWorkWithNonHashCodeEquals.kt
Last active April 3, 2023 07:59
DoesHashMapWorkWithNonHashCodeEquals.kt
import java.util.UUID
var isEqualsFunctionCalled = false
data class KeyObj(val uuid: UUID = UUID.randomUUID()) {
override fun equals(other: Any?): Boolean {
isEqualsFunctionCalled = true
return super.equals(other)
import java.util.UUID
import kotlin.system.measureTimeMillis
fun main() {
fun newRandomString() = UUID.randomUUID().toString()
val list = (0..100).map { newRandomString() }.toList()
val times = 100000
val a = measureTimeMillis {
repeat(times) {
list.forEach { }
@Bruce0203
Bruce0203 / FastIterator.kt
Last active March 13, 2023 09:30
performance optimized forEach in Kotlin (exclude LinkedList case)
inline fun <T> List<T>.fastForEach(callback: (T) -> Unit) {
var n = 0
while (n < size) callback(this[n++])
}
inline fun <T> Array<T>.fastForEach(callback: (T) -> Unit) {
var n = 0
while (n < size) callback(this[n++])
}
miniGames:
테스트:
maxPlayers: 20
maxStartPlayers: 1
waitForStartTime: 100
gameTime: 100
repeatList:
- wait
- timer
repeats: