Skip to content

Instantly share code, notes, and snippets.

// for i in 0..v.len() {sum += v[i];}
// https://play.rust-lang.org/?version=stable&mode=release&edition=2015&gist=a234fd242a39e0e33d1775ba986a7f50
playground::main:
pushq %r14
pushq %rbx
subq $152, %rsp
movq $0, 16(%rsp)
movl $800000000, %edi
movl $8, %esi
callq __rust_alloc@PLT
@yohhoy
yohhoy / yuvrgb.md
Last active March 29, 2024 00:19
RGB <=> YCbCr(YPbPr) color space conversion
Y  = a * R + b * G + c * B
Cb = (B - Y) / d
Cr = (R - Y) / e
BT.601 BT.709 BT.2020
a 0.299 0.2126 0.2627
b 0.587 0.7152 0.6780
@yohhoy
yohhoy / unscoped_enum.rs
Created July 30, 2018 13:30
UnscopedEnum
//--------------------------------------------------------
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[repr(u8)]
enum UnscopedEnum {
AAA = 1,
BBB = 2,
CCC = 3,
}
const AAA: UnscopedEnum = UnscopedEnum::AAA;
@yohhoy
yohhoy / as_num.rs
Created July 6, 2018 07:45
Numeric cast (as operator) in generics
trait FromU32 {
fn from_u32(v: u32) -> Self;
}
macro_rules! impl_from_u32 {
($($ty:ty)*) => {
$(
impl FromU32 for $ty {
#[inline]
fn from_u32(v: u32) -> $ty {
#!/usr/bin/env python3
# https://ja.stackoverflow.com/questions/45180/
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.colors as colors
n = 10
x_list = np.array(list(range(n*2)))
t_list = np.array(list(range(n*2)))
@yohhoy
yohhoy / m2tsdump.sh
Created June 6, 2018 06:19
hexdump MPEG-2 TS/PAT
# PAT(PID=0x0000)
xxd -s ${offset} -c 188 -ps input.ts | grep -E "^47[46]000"
@yohhoy
yohhoy / sleepsort2.cpp
Last active August 10, 2019 05:14
"Sleep Sort" implementation with C++ Coroutines TS
#include <condition_variable>
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
#include <utility>
#include <vector>
#include <experimental/coroutine>
@yohhoy
yohhoy / delayqueue.cpp
Last active July 29, 2023 14:59
C++ delay queue - unbound blocking queue with delay of element deque (like Java's java.util.concurrent.DelayQueue)
// delayqueue.cpp -- C++ delay queue
// Copyright (c) 2018 yohhoy
//
// Boost Software License, Version 1.0
// https://www.boost.org/LICENSE_1_0.txt
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <utility>
#include <vector>
@yohhoy
yohhoy / sleepsort.cpp
Created April 11, 2018 08:44
"Sleep Sort" implementation with C++ Coroutines TS
#include <condition_variable>
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
#include <utility>
#include <vector>
#include <experimental/coroutine>
@yohhoy
yohhoy / jls10-var.txt
Created April 1, 2018 13:43
var x = new ArrayList<>();
>>
15.9. Class Instance Creation Expressions
A class instance creation expression is a poly expression (§15.2) if it uses the diamond form for type arguments to the class, and it appears in an assignment context or an invocation context (§5.2, §5.3). Otherwise, it is a standalone expression.
We say that a class is instantiated when an instance of the class is created by a class instance creation expression. Class instantiation involves determining the class to be instantiated (§15.9.1), the enclosing instances (if any) of the newly created instance (§15.9.2), and the constructor to be invoked to create the new instance (§15.9.3).
<<
>>
15.9.1. Determining the Class being Instantiated