Skip to content

Instantly share code, notes, and snippets.

@smhanov
smhanov / OpenType.ts
Last active December 17, 2023 04:58
Here is my implementation of a TrueType font reader in Typescript. You can read a font directly from an ArrayBuffer, and then call drawText() to draw it. See my article http://stevehanov.ca/blog/index.php?id=143. The second file, OpenType.ts is the same thing but it handles more TrueType files. It is also more coplex
// To see this run, you first stub out these imports. Then put the file in a Uint8Array.
// let slice = new Slice(array);
// let font = new OTFFont(slice);
// Then you can call methods like font.drawText(canvasContext, )
//
//
import { ICanvasContext } from "./ICanvasContext"
import { log as Log } from "./log"
const log = Log.create("OPENTYPE");
@yegappan
yegappan / VimScriptForPythonDevelopers.MD
Last active January 12, 2024 10:51
Vim script for Python Developers

Vim Script for Python Developers

This is a guide to Vim Script development for Python developers. Sample code for the various expressions, statements, functions and programming constructs is shown in both Python and Vim Script. This is not intended to be a tutorial for developing Vim scripts. It is assumed that the reader is familiar with Python programming.

For an introduction to Vim Script development, refer to usr_41.txt, eval.txt and Learn Vimscript the Hard Way

For a guide similar to this one for JavaScript developers, refer to Vim Script for the JavaScripter

This guide only describes the programming constructs that are present in both Python and Vim. The constructs that are unique to Vim (e.g. autocommands, [key-mapping](https://vimhelp.org/map.txt.html#key-m

# Originally written on 2017-04-26 19:03.
# Welcome to my fancy Shift JIS explanation and simple implementation in Python.
#
# If you haven't heard of Shift JIS, it's a single or double-byte encoding for
# the JIS X 0201 and JIS X 0208 character sets, a bit like UTF-8 is for Unicode.
#
# The key feature of Shift JIS is being able to use both character sets at once,
# retaining legacy half-width ASCII and Katakana characters from JIS X 0201.
#
@kirienko
kirienko / reverse_imposing.py
Last active March 3, 2024 08:59 — forked from tshrinivasan/split-page.py
Split a PDF vertically, used for imposed scanned double sided PDF pages
# see https://stackoverflow.com/questions/51973437/reverse-pdf-imposition
import copy
import sys
import math
import pyPdf
"""
Reverse imposing:
@josephg
josephg / 0dedict.py
Last active February 16, 2024 08:33
Apple dictionaries
# Thanks to commenters for providing the base of this much nicer implementation!
# Save and run with $ python 0dedict.py
# You may need to hunt down the dictionary files yourself and change the awful path string below.
# This works for me on MacOS 10.14 Mohave
from struct import unpack
from zlib import decompress
import re
filename = '/System/Library/Assets/com_apple_MobileAsset_DictionaryServices_dictionaryOSX/9f5862030e8f00af171924ebbc23ebfd6e91af78.asset/AssetData/Oxford Dictionary of English.dictionary/Contents/Resources/Body.data'
f = open(filename, 'rb')
@zr-tex8r
zr-tex8r / gen_chart.pl
Created July 20, 2014 01:07
To create the glyph chart of Source Han Sans JP
use strict;
my $srcbase = "shsglyphs";
my $tfmbase = "sourcehans-r-j49";
our @shs_width;
require "shs_width.pl";
my $maxcc = $#shs_width; $shs_width[0] = -1;
my (@wdi, @wdr);
{
my (%rp);
%!PS-Adobe-3.0 Resource-CMap
%%DocumentNeededResources: ProcSet (CIDInit)
%%IncludeResource: ProcSet (CIDInit)
%%BeginResource: CMap (UniSourceHanSansJP-UTF16-H)
%%Title: (UniSourceHanSansJP-UTF16-H Adobe Identity 0)
%%Version: 1.000
%%Copyright: -----------------------------------------------------------
%%Copyright: Copyright 1990-2014 Adobe Systems Incorporated.
%%Copyright: All rights reserved.
%%Copyright: