This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pack bytes into valid UTF-16 string | |
// | |
// strategy: | |
// | |
// * using ESC as the escape character | |
// * if there is ESC in the bytes, double it | |
// * if there is unmatched surrogate pair, mark it by the escape character | |
// | |
// 0x007f: escape, because it's rare but still only one utf-8 byte. | |
// To escape itself, use 0x007f 0x08ff (two bytes utf-8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const outof = <T extends BaseSchema, R, | |
O = T extends BaseSchema<any, infer O> ? O : never, | |
>(schema:T, value:unknown, then?:(value:O) => R): value is O => { | |
const {issues, output} = safeParse(schema, value); | |
if (issues && issues.length > 0) return false; | |
if (then) then(output as O); | |
return true; | |
}; | |
// USAGE example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const waiter: { | |
<T, R, A extends any[]>( | |
w:Waitable<T>, done:(x:T, ...args:A) => Promise<R>|R | |
): (...args:A) => Promise<R>; | |
<R, A extends any[], T=void|undefined>( | |
w:Waitable<T>, done:(...args:A) => Promise<R>|R | |
): (...args:A) => Promise<R>; | |
} = <T, R, A extends any[]>(w:Waitable<T>, done:{ | |
(x:T, ...args:A):Promise<R>|R; | |
(...args:A):Promise<R>|R; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { | |
FormStore, FieldValues, ResponseData, FormErrors, FieldPath, FieldArrayPath, | |
SetResponseOptions, | |
} from '@modular-forms/qwik'; | |
import { | |
getValues, validate, setResponse, FormError, setError, | |
} from '@modular-forms/qwik'; | |
import { type Maybe } from '~/utils'; | |
type ErrorResponseOptions = SetResponseOptions & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
opts, files = ARGV.partition {|a| a =~ /^-/} | |
first, *middle, last = files | |
base = File.expand_path File.dirname(first) | |
to = File.expand_path File.join base, last | |
system ['mv', *opts, first, *middle, to].join ' ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'shellwords' | |
end | |
CHATGPT_URI = "https://chat.openai.com/chat" | |
def get_page_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// style-1 | |
scanner->sis = grn_scan_info_build(ctx, | |
scanner->expr, | |
&(scanner->n_sis), | |
op, | |
record_exist); | |
// style-2 | |
scanner->sis = | |
grn_scan_info_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.<collections>.aggregate({$indexStats:{}})._batch.reduce((h,i) => {h[i.spec.name] = i.accesses.ops; return h}, {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "em-synchrony" | |
def foo | |
fiber = Fiber.current | |
EM::Timer.new 3 do | |
fiber.resume "foo" | |
end | |
Fiber.yield | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% time seconds usecs/call calls errors syscall | |
------ ----------- ----------- --------- --------- ---------------- | |
26.90 0.257079 6 41582 rt_sigprocmask | |
16.05 0.153354 7 20767 write | |
14.84 0.141774 7 20773 getsockopt | |
13.86 0.132456 6 20768 sched_yield | |
13.30 0.127114 18 6885 select | |
9.32 0.089066 6 13834 clock_gettime | |
5.53 0.052820 8 6986 50 read | |
0.09 0.000887 29 31 writev |
NewerOlder