Skip to content

Instantly share code, notes, and snippets.

View yapcheahshen's full-sized avatar

yap cheah shen yapcheahshen

View GitHub Profile
@yapcheahshen
yapcheahshen / cnumber.jsee
Last active April 10, 2023 11:05
將Emeditor 選取區的中文數字轉為number
/* to install, EmEditor Macro menu, customize, add , select cnumber.jsee */
if (!document.selection.IsEmpty) {
var lines=document.selection.Text.split(/\r?\n/);
var out=[];
for (var line=0;line<lines.length;line++) {
var val=parseInt(lines[line]
.replace(/百([二三四五六七八九])十/,'$1十')
.replace(/百十$/,'10')
.replace(/百十/,'1')
.replace(/百$/,'00')
import {openBasket,nodefs} from 'pitaka/cli';
await nodefs ; //等 fs 準備好
const zh= await openBasket('mzd'); //原文
const en= await openBasket('mzd-en'); //英文版
const [start,end]= zh.getPageRange('antho.1'); // 取得 第一篇文章 中國社會各階級的分析 的範圍,
await zh.prefetchLines(start,end); //預讀這個範圍
await en.prefetchLines(start,end); //英版一致
for (let i=start;i<end;i++) { //遍歷
const zhline=zh.getLine(i); //抓取行
const enline=en.getLine(i);
<html>
<style>
.c {background:rgba(255,64,64,0.3)}
</style>
<body>
00000<span class="c">11111<span class="c">22222<span class="c">33<span class="c">4444</span>3333</span>2222</span>11111</span>000000
</body>
<html>
@yapcheahshen
yapcheahshen / bigramjs
Created May 5, 2012 02:47
calculate bigram in a text file
/*
text file cannot contain surrogate due to bugs in node.js
*/
var fs = require('fs');
var total_size=0;
var filetoarraySync = function (filename, encoding) { //array
encoding = encoding || 'utf8';
var data = fs.readFileSync(filename, encoding);