Skip to content

Instantly share code, notes, and snippets.

View cjxgm's full-sized avatar
🦧
Recovering...

Giumo Clanjor (哆啦比猫/兰威举) cjxgm

🦧
Recovering...
View GitHub Profile
@cjxgm
cjxgm / hack-simple-widget-crash.patch
Created February 20, 2017 06:05
Dirty fix TeXmacs 1.99.5 crashing/freezing/segfault when closing any dialog that contains a TeXmacs widget (like New Style Font Selection, Log, New Macros / Edit Macros)
diff -Naur TeXmacs-1.99.5-src/src/Plugins/Qt/qt_simple_widget.cpp TeXmacs-1.99.5-src-fix-simple-widget-crash/src/Plugins/Qt/qt_simple_widget.cpp
--- TeXmacs-1.99.5-src/src/Plugins/Qt/qt_simple_widget.cpp 2016-07-08 01:56:55.000000000 +0800
+++ TeXmacs-1.99.5-src-fix-simple-widget-crash/src/Plugins/Qt/qt_simple_widget.cpp 2017-02-20 13:53:30.741575287 +0800
@@ -615,6 +615,10 @@
iterator<pointer> i = iterate(qt_simple_widget_rep::all_widgets);
while (i->busy()) {
qt_simple_widget_rep *w = static_cast<qt_simple_widget_rep*>(i->next());
+ if (w->canvas() == NULL) {
+ all_widgets->remove ((pointer) w);
+ continue;
@cjxgm
cjxgm / cbi.cc
Created August 17, 2016 15:35
Capped back insert iterator (C++)
#include <utility> // std::forward
#include <iterator> // std::iterator, std::output_iterator_tag
template <class Container>
struct capped_back_insert_iterator final: std::iterator<std::output_iterator_tag, void, void, void, void>
{
capped_back_insert_iterator(Container & con, int cap)
: con{con}, capacity{cap}, size{0} {}
@cjxgm
cjxgm / keyboard.cc
Last active May 1, 2016 13:53
Detect simulteneous keydown/up events in tty in Linux, using evdev directly
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "scope-exit.hh"
@cjxgm
cjxgm / cl.hh
Created September 24, 2015 16:34
opencl helloworld
// The official OpenCL C++ wrapper is just a rubbish.
// It doesn't mean mine is good.
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h> // ml:lib += OpenCL
#include <type_traits>
#include <stdexcept>
#include <memory>
#include <string>
@cjxgm
cjxgm / decode-utf8.cc
Created July 19, 2015 13:39
decode utf8 to codepoints. assuming input is absolutely valid 1~6 bytes utf-8 encoded string.
#include <cstdint>
#include <cstdio>
namespace
{
auto decode(char const* & s)
{
std::uint32_t code{};
switch (auto c = static_cast<unsigned char>(*s++)) {
case 0b0'0000000 ... 0b0'1111111: code = c; break;
@cjxgm
cjxgm / font-prober.cc
Last active August 29, 2015 14:25
An easy-to-use C++14 header-only library for listing and querying installed fonts.
#pragma once
#include <fontconfig/fontconfig.h>
#include <vector>
#include <string>
#include <memory>
namespace font_prober
{
struct finalizer
@cjxgm
cjxgm / raymarch-100-ascii.lua
Last active July 9, 2021 23:00
raymarching ascii-art rendering in 100-lines of lua
---------------------------------------------------------------------------
-- vector
local vector = (function()
local mt = {}
mt.__index = mt
local vector
vector = function(x, y, z)
if type(x) == 'table' then
@cjxgm
cjxgm / luaray.lua
Last active August 29, 2015 14:24
one file distance field raymarching (asciiart) renderer written in lua
---------------------------------------------------------------------------
-- vector
local make_vector = function()
local mt = {}
local vector
vector = function(x, y, z)
if type(x) == 'table' then
return setmetatable(x, mt)
@cjxgm
cjxgm / tag_stack.cc
Last active August 29, 2015 14:22
tag stack with hash identifier
#include <string> // with std::hash<std::string>
#include <utility> // for std::move
#include <sstream>
#include <vector>
#include <iomanip> // for std::quoted
namespace tag_stack_detail
{
@cjxgm
cjxgm / is_ptr.cc
Last active August 29, 2015 14:19
template <class T> constexpr auto is_ptr = false;
template <class T> constexpr auto is_ptr<T*> = true;
int main()
{
static_assert(is_ptr<int*>, "int* must be ptr");
static_assert(!is_ptr<int>, "int must not be ptr");
}