Skip to content

Instantly share code, notes, and snippets.

View sky0014's full-sized avatar
🚩
550-W

sky0014 sky0014

🚩
550-W
  • Wuhan
View GitHub Profile
@sky0014
sky0014 / webpack.config.js
Created December 29, 2023 07:45
Webpack exclude part of node modules
{
test: /\.js$/,
exclude: /node_modules\/(?!(MY-MODULE|ANOTHER-ONE)\/).*/,
},
@sky0014
sky0014 / useDarkMode.ts
Created September 1, 2023 03:46
React hooks that query is it in dark mode.
import { useEffect, useMemo, useState } from "react";
const DARK_MODE_SCHEME = "(prefers-color-scheme: dark)";
export function getIsDarkMode() {
return window.matchMedia(DARK_MODE_SCHEME).matches;
}
export function useDarkMode() {
const initValue = useMemo(getIsDarkMode, []);
@sky0014
sky0014 / .bashrc
Last active July 25, 2023 10:04
proxy for shell (Add to ~/.bashrc)
# useage: proxy curl www.google.com
proxy() {
http_proxy=127.0.0.1:1080 https_proxy=127.0.0.1:1080 $*
}
@sky0014
sky0014 / sdp-transform.ts
Last active November 28, 2022 12:48
transform sdp old & new format
if (Browser.firefox || this.options.isSDPOldFormat) {
try {
const obj = sdpTransform.parse(sdp);
// workaround: 火狐替换大于uint64的session_id(可能由老版本chrome或sdk发出)
obj.origin.sessionId = 1;
// workaround: 火狐datachannel新旧格式支持问题
// workaround: 旧版本chrome同样不支持新的sdp格式,需要转换
const isOld = !!obj.media[0].sctpmap;
if (this.options.isSDPOldFormat) {
if (!isOld) {
@sky0014
sky0014 / h264.ts
Created August 8, 2022 09:06
convert annex-b format to normal nalu
if (v.getUint32(offset + lengthSize) === 1) {
const bytes = new Uint8Array(
arrayBuffer,
dataOffset + offset + 4,
naluSize
);
const nals = parseNal({
codec: Codec.H264,
bytes
});
@sky0014
sky0014 / UnionToIntersection.ts
Created February 21, 2022 08:53
Magical UnionToIntersection of typescript
// from https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type by jcalz
type UnionToIntersection<U> =
(U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never
@sky0014
sky0014 / issue-collect.md
Last active December 11, 2019 16:29
issue收藏夹
@sky0014
sky0014 / flv-demuxer.ts
Created March 1, 2019 03:51
Large timestamp gap detected; may cause AV sync to drift check and aac frame generate code.
// AAC raw frame data
let dts = this._timestampBase + ts;
// check large timestamp gap caused av drift
if (this._expectTsAudio === -1) {
this._expectTsAudio = dts; // set base ts
}
let generated = false;
const delta = dts - this._expectTsAudio;