Skip to content

Instantly share code, notes, and snippets.

View ChasLui's full-sized avatar
🦍

ChasLui ChasLui

🦍
View GitHub Profile
@ninely
ninely / main.py
Last active April 19, 2024 11:04
Langchain with fastapi stream example
"""This is an example of how to use async langchain with fastapi and return a streaming response.
The latest version of Langchain has improved its compatibility with asynchronous FastAPI,
making it easier to implement streaming functionality in your applications.
"""
import asyncio
import os
from typing import AsyncIterable, Awaitable
import uvicorn
from dotenv import load_dotenv
@gregveres
gregveres / line-height.ts
Created May 4, 2022 12:20
line-heights for tiptap 2
import { Extension } from "@tiptap/core";
export interface LineHeightOptions {
types: string[];
heights: string[];
defaultHeight: string;
}
declare module "@tiptap/core" {
interface Commands<ReturnType> {
@gregveres
gregveres / back-color.ts
Created May 3, 2022 23:26
background-color for tiptap 2
import { Extension } from "@tiptap/core";
import "@tiptap/extension-text-style";
export type ColorOptions = {
types: string[];
};
declare module "@tiptap/core" {
interface Commands<ReturnType> {
backColor: {
@gregveres
gregveres / font-size.ts
Created May 3, 2022 22:34
font-size for tiptap 2
import { Extension } from "@tiptap/core";
import "@tiptap/extension-text-style";
export type FontSizeOptions = {
types: string[];
};
declare module "@tiptap/core" {
interface Commands<ReturnType> {
fontSize: {
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active October 6, 2023 18:39
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
import path from 'path'
import vue from '@vitejs/plugin-vue'
import icons from 'vite-plugin-svg-icons'
import inspect from 'vite-plugin-inspect'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import createDebugger from 'debug'
import { defineConfig } from 'laravel-vite'
export default defineConfig()
@nuclearglow
nuclearglow / convert-arraybuffer.js
Created January 26, 2018 10:30
ArrayBuffer <-> JSON <-> ArrayBuffer
// array buffer to JSON
const dataString JSON.stringify(Array.from(new Uint8Array(arrayBuffer)));
// send around
// JSON to ArrayBuffer
new Uint8Array(JSON.parse(dataString)).buffer
@wangkuan0818
wangkuan0818 / 微信内置浏览器UserAgent的判断
Last active August 23, 2023 01:15
微信内置浏览器UserAgent的判断
// 检测浏览器的 User Agent 应该是非常简单的事情
// 微信在 Android 下的 User Agent
mozilla/5.0 (linux; u; android 4.1.2; zh-cn; mi-one plus build/jzo54k) applewebkit/534.30 (khtml, like gecko) version/4.0 mobile safari/534.30 micromessenger/5.0.1.352
// 微信在 iPhone 下的 User Agent
mozilla/5.0 (iphone; cpu iphone os 5_1_1 like mac os x) applewebkit/534.46 (khtml, like gecko) mobile/9b206 micromessenger/5.0
// 通过javascript判断
// 很容易看出来,微信的 User Agent 都有‘micromessenger’字符串标示,我们判断是否含有这些字符串就OK了
function isWeixinBrowser(){
@GoodBoyDigital
GoodBoyDigital / pixi-performance-tips.txt
Last active June 29, 2023 13:40
Pixi Performance Tips
Global :
- Only optimize when you need to! Pixi can handle a fair amount of content off the bat.
- Be mindful of the complexity of your scene. The more objects you add the slower things will end up.
- Order can help, for example sprite / graphic / sprite / graphic is slower than sprite / sprite / graphic / graphic
- Some older mobile devices run things a little slower. passing in the option 'legacy:true' to the renderer can help with performance
- Culling, is disabled by default as its often better to do this at an application level. If you are GPU it will improve performance, if you are CPU bound - it will degrade performance
Sprites:
- Use spritesheets where possible to minimize total textures
- Sprites can be batched with up to 16 different textures (dependent on hardware)
@dmonad
dmonad / index.html
Last active March 22, 2021 16:26
You can use an existing socket.io connection in Yjs. Works with y-websockets-client >= 8.0.6
<!DOCTYPE html>
<html>
<body>
<textarea style="width:80%;" rows=40 id="text1" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
<textarea style="width:80%;" rows=40 id="text2" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
<script src="bower_components/yjs/y.js"></script>
<script src="bower_components/y-websockets-client/y-websockets-client.js"></script>
<script src="./index_1.js"></script>
</body>
</html>