Skip to content

Instantly share code, notes, and snippets.

@KoKuToru
KoKuToru / file_fixer.cpp
Last active May 12, 2022 17:56
File Fixer
// g++ file_fixer.cpp --std=c++20 -O3 -o file_fixer
// usage: ./file_fixer file_to_fix file_ref_a file_ref_b ....
#include <string_view>
#include <iostream>
#include <span>
#include <vector>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
@KoKuToru
KoKuToru / utf8_utf16.cpp
Created May 1, 2022 14:22
Convert UTF8 to UTF16
#include <string>
#include <string_view>
#include <iostream>
#include <tuple>
std::tuple<std::u8string_view, char32_t> decode_u8_charpoint(std::u8string_view input) {
// XXX: silently accept invalid UTF8
if ((input.at(0) & 0b10000000) == 0b00000000) {
return {
input.substr(1),
@KoKuToru
KoKuToru / variant.cpp
Last active August 19, 2021 20:03
C++ Variant
//#include <iostream>
#include <type_traits>
#include <string>
#include <stdexcept>
#define FLATTEN __attribute__((flatten))
#define INLINE __attribute__((always_inline))
#define INLINE_FLATTEN __attribute__((always_inline, flatten))
using size_t = std::size_t;
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@service router;
@action async transition(route) {
try {
@KoKuToru
KoKuToru / buffer.cpp
Last active August 8, 2020 07:50
OpenGL Buffer (4.5?!)
//g++ test.cpp `sdl2-config --cflags --libs` -lGLEW -lGL
#define NO_SDL_GLEXT
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <stdexcept>
#include <iostream>
template<typename T> struct Vec2 {
T x;
https://stackoverflow.com/questions/46234722/initialize-keras-placeholder-as-input-to-a-custom-layer
https://github.com/bckenstler/CLR
https://blog.evjang.com/2016/11/tutorial-categorical-variational.html
https://www.freepik.com/index.php?goto=2&k=patterns&isCat=1&isKeyword=1&type=1&vars=1&is_selection=1
https://stackoverflow.com/a/44906668/362904
import Ember from 'ember';
const events = [
//keyboard
'keydown',
'keyup',
'keypress',
//im
'compositionstart',
'compositionupdate',
@KoKuToru
KoKuToru / rerender-debug.css
Created September 17, 2016 11:51
Little helper for Ember rerender visualisation
[rerender] {
transition: background 1s;
}
[rerender="2"] {
background: #ffd7d7 !important;
transition: background 0s;
}
[rerender="1"] {
background: #d7deff !important;
transition: background 0s;
function jsonToEmber(obj) {
if (obj instanceof Array) {
return Ember.A(obj.map(y => jsonToEmber(y)));
} else if (obj instanceof Object) {
let tmp = {};
for (const x of Object.keys(obj)) {
if (obj[x] instanceof Array) {
tmp[x] = Ember.A(obj[x].map(y => jsonToEmber(y)));
} else if (obj[x] instanceof Object) {
tmp[x] = jsonToEmber(obj[x]);