Skip to content

Instantly share code, notes, and snippets.

// callee.m iOS Native(Objective-C) class
@interface NativeType
- (void)method:(int)arg;
@end

@implementation NativeType
// ...
@end
@yohhoy
yohhoy / invokeObjC.c
Created June 14, 2019 18:44
invoke Obj-C from pure-C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <objc/message.h>
SEL sel_propSetter(Class clazz, const char* pname)
{
char* attr = property_copyAttributeValue(class_getProperty(clazz, pname), "S");
@yohhoy
yohhoy / ver.cpp
Created April 18, 2019 15:57
compiler version snippet
#if defined(__clang__)
#pragma message "Clang " __VERSION__
#elif defined(__GNUC__)
#pragma message "GCC " __VERSION__
#elif defined(_MSC_VER)
// https://qiita.com/yumetodo/items/8c112fca0a8e6b47072d
#define STR(s) #s
#define DUMP(s) #s "=" STR(s)
#pragma message ("MSVC " DUMP(_MSC_VER) " " DUMP(_MSC_FULL_VER))
#endif
// 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 September 24, 2025 06:32
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>