Skip to content

Instantly share code, notes, and snippets.

@jtanx
jtanx / README.md
Last active December 28, 2019 08:24
Partial OpenWRT NB604N support

NB604N support

NOTE: Superceded by openwrt/openwrt#2655

The issue on persisting data to flash is resolved by the patches to spi-nor.c in that PR.

Mostly works, but I can't get changes to persist to flash, so settings are lost on reboot. Looking in dmesg there's some jffs2 issues that I can't work out.

Use the brcmsmac driver for wireless support, delete all references to the b43 driver, or you will end up with at best only 802.11g support instead of 802.11n.

@jtanx
jtanx / clang-format.xt
Created March 11, 2019 20:09
Clang format
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Always, AccessModifierOffset: -4, IndentWidth: 4, CompactNamespaces: true, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: true, ColumnLimit: 0, TabWidth: 4, PointerAlignment: Left, AlignAfterOpenBracket: DontAlign, BreakBeforeBraces: Custom, BraceWrapping: {AfterClass: true, AfterControlStatement: true, AfterEnum: true, AfterFunction: true, AfterNamespace: false, AfterObjCDeclaration: true, AfterStruct: true, AfterUnion: true, BeforeCatch: true, BeforeElse: true, IndentBraces: false}, BreakConstructorInitializers: BeforeComma}",
@jtanx
jtanx / gtk.c
Last active March 26, 2019 09:12
messing around with gtk
#include <gtk/gtk.h>
#include <stdbool.h>
typedef struct ggtkwindow *GGTKWindow;
// GGtkWindow GObject declaration
#define GGTK_TYPE_WINDOW ggtk_window_get_type()
G_DECLARE_FINAL_TYPE(GGtkWindow, ggtk_window, GGTK, WINDOW, GtkLayout)
@jtanx
jtanx / ggtkwindow.c
Created March 24, 2019 03:16
Minimal GTK custom widget implementation
#include "ggtkwindow.h"
// Define the structure of the type
struct _GGtkWindow
{
GtkLayout parent_instance;
// private data here
// because this is a final type, I don't need to use G_DEFINE_TYPE_WITH_PRIVATE
// and jump through all the hoops that entails. That is required
@jtanx
jtanx / gb12345.txt
Created April 6, 2019 09:32
gb12345 FontForge
# gb12345 based on https://github.com/fontforge/fontforge/blob/35de97a/plugins/gb12345.c
0x0 0x0
0x1 0x1
0x2 0x2
0x3 0x3
0x4 0x4
0x5 0x5
0x6 0x6
0x7 0x7
0x8 0x8
@jtanx
jtanx / makecombiners.h
Created July 21, 2019 02:38
Combiners parsing for combiners.h
#!/usr/bin/env python3
import sys,os,re
# http://www.unicode.org/reports/tr44/#Canonical_Combining_Class_Values
COMBIN = {
0x000: '0',
0x001: 'FF_UNICODE_Overstrike',
0x202: 'FF_UNICODE_Below|FF_UNICODE_Touching',
0x214: 'FF_UNICODE_Above|FF_UNICODE_Touching',
@jtanx
jtanx / CustomInstallPath.cmake
Created August 3, 2019 07:22
Custom library install path for MacOS and CMake
# Suppose under certain circumstances you want to set the library path explicitly to something, but
# in the usual case, you would like it to remain as an rpath.
# This adds a variable to the install script that can be overridden
install(CODE "
if(NOT DEFINED CUSTOM_LIBRARY_PREFIX)
set(CUSTOM_LIBRARY_PREFIX \"@rpath\")
endif()
")
set_property(TARGET my_target PROPERTY INSTALL_NAME_DIR "\${CUSTOM_LIBRARY_PREFIX}")
@jtanx
jtanx / conns.yml
Created March 9, 2020 10:16
Service discovery descriptor
config:
min_port: 1000
max_port: 2000
shmem:
default:
- proc_a
- proc_b
tcp:
default:
- proc_a
@jtanx
jtanx / pad.cmake
Last active May 26, 2022 23:11
Padding a string in cmake
function(pad_string output str padchar length)
string(LENGTH "${str}" _strlen)
math(EXPR _strlen "${length} - ${_strlen}")
if(_strlen GREATER 0)
if(${CMAKE_VERSION} VERSION_LESS "3.14")
unset(_pad)
foreach(_i RANGE 1 ${_strlen}) # inclusive
string(APPEND _pad ${padchar})
endforeach()
@jtanx
jtanx / splitbins.py
Created March 21, 2021 09:17
3 vs 4-level lookup tables for unicode data
# Based on the algorithm in https://github.com/python/cpython/blob/master/Tools/unicode/makeunicodedata.py
import math
import sys
def getsize(data):
# return smallest possible integer size for the given array
maxdata = max(data)
if maxdata < 256:
return 1