Skip to content

Instantly share code, notes, and snippets.

View lancetw's full-sized avatar
🐈

Hsin-lin Cheng lancetw

🐈
View GitHub Profile
@lancetw
lancetw / longest_chinese_tokens_gpt4o.py
Created May 14, 2024 13:36 — forked from ctlllll/longest_chinese_tokens_gpt4o.py
Longest Chinese tokens in gpt4o
import tiktoken
import langdetect
T = tiktoken.get_encoding("o200k_base")
length_dict = {}
for i in range(T.n_vocab):
try:
length_dict[i] = len(T.decode([i]))
except:

News APIs:

  • Fetch: [GET] -> /news/:id
  • List: [GET] -> /news/list
  • Add: [POST] -> /news
  • Update: [POST] -> /news/:id
  • Remove: [DELETE] -> /news/:id

// ref: https://gitlab.com/manning-fpcpp-book/code-examples/-/blob/master/chapter-01/count-lines-transform/main.cpp
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <ranges>
this.query = (filter: Filter) =>
Observable.from(
this.api.getData(filter).switchMap((res) => {
this.setData(res)
})
)
var alphabetBoardPath=function(f){var g=new Map(Array.from("abcdefghijklmnopqrstuvwxyz").map(function(a,c){return[a,{x:c/5|0,y:c%5|0}]})),d=function(a,c){return 0>=c?"":a.repeat(c)},a={x:0,y:0};return Array.from(f).reduce(function(e,c){var b=g.get(c);e.push(b.y<a.y?d("L",a.y-b.y):"",b.x<a.x?d("U",a.x-b.x):"",b.x>a.x?d("D",b.x-a.x):"",b.y>a.y?d("R",b.y-a.y):"","!");a=b;return e},[]).join("")};
const alphabetBoardPath = (target) => {
const layout = 5
const hashMap = new Map(Array.from("abcdefghijklmnopqrstuvwxyz").map((c, i) => [ c, {x: (i / layout) | 0, y: i % layout | 0}]))
const repeat = (s, n) => (n <= 0 ? '' : s.repeat(n))
let p0 = { x: 0, y: 0 }
return Array.from(target).reduce((ret, t) => {
const p = hashMap.get(t)
ret.push(p.y < p0.y ? repeat('L', p0.y - p.y) : '', p.x < p0.x ? repeat('U', p0.x - p.x) : '', p.x > p0.x ? repeat('D', p.x - p0.x) : '', p.y > p0.y ? repeat('R', p.y - p0.y) : '', '!')
p0 = p
return ret
const alphabetBoardPath = (target) => {
const layout = 5
const hashMap = new Map(Array.from("abcdefghijklmnopqrstuvwxyz")
.map((c, i) => [ c, {x: (i / layout) | 0, y: i % layout | 0}]))
const repeat = (s, n) => (n <= 0 ? '' : s.repeat(n))
let p0 = { x: 0, y: 0 }
const ret = Array.from(target).reduce((ret, t) => {
const p = hashMap.get(t)
const delay = (delay) => () => new Promise((resolve, reject) => setTimeout(resolve, delay))
const main = () => f1().then(f2).catch(f3)
const f1 = () => new Promise((resolve, reject) => ret ? resolve() : reject())
const f2 = () => Promise.resolve('f2')
const f3 = () => Promise.resolve('f3')
let ret = true
const next = () => ret = !ret
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["dom", "es2015"],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
@lancetw
lancetw / form2obj.ts
Last active September 26, 2018 11:57
let user = new User(filterByProps(form, [
'username',
'displayname'
]))
function filterByProps(obj: any, props: string[]): any {
if (!props) return obj
let ret = {}
Object.keys(obj).forEach(key => {
if (props.some(prop => prop === key)) {