Skip to content

Instantly share code, notes, and snippets.

View ahonn's full-sized avatar
🐵
Happy Hacking

Yuexun ahonn

🐵
Happy Hacking
View GitHub Profile
import fs from 'fs';
import path from 'path';
import { PDFLoader } from 'langchain/document_loaders/fs/pdf';
import { OpenAI } from 'langchain/llms/openai';
import { OpenAIEmbeddings } from 'langchain/embeddings/openai';
import { SupabaseVectorStore } from 'langchain/vectorstores/supabase';
import { RetrievalQAChain } from 'langchain/chains';
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { createClient } from '@supabase/supabase-js';
import * as dotenv from 'dotenv';
const { Project, ts } = require('ts-morph');
const path = require('path');
const filePath = path.join(process.cwd(), './simple_types.ts');
const project = new Project();
project.addExistingSourceFile(filePath);
const sourceFile = project.getSourceFile(filePath);
const enums = sourceFile.getEnums();
query {
repository(owner: "ahonn", name: "blog") {
object(expression: "master:README.md") {
...on Blob {
text
}
}
defaultBranchRef {
target {
... on Commit {
function fish_default_mode_prompt --description "Display the default mode for the prompt"
# Do nothing if not in vi mode
if test "$fish_key_bindings" = "fish_vi_key_bindings"
or test "$fish_key_bindings" = "fish_hybrid_key_bindings"
switch $fish_bind_mode
case default
set_color --bold --background red white
echo '[N]'
case insert
set_color --bold --background green white
@ahonn
ahonn / PagerView.swift
Created December 26, 2019 08:54 — forked from mecid/PagerView.swift
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
const onPlotClick = (event) => {
const { data } = event;
if (data) {
const { category } = data.point;
if (category !== query.category) {
setTimeout(() => {
const geom = _.first(chartRef.current.get('geoms'));
const item = geom.get('data').find(_.propEq('category', category));
geom.setSelected(item);
Function.prototype.bind = function (ctx) {
var self = this;
var nativeSlice = Array.prototype.slice;
var args = nativeSlice.call(arguments, 1);
return function () {
var bindArgs = args.concat(nativeSlice.call(arguments));
return self.apply(ctx, bindArgs);
}
}
@ahonn
ahonn / JavaScript deepClone.js
Last active September 25, 2019 10:09
implement object deep clone
function deepClone(source, hash = new WeakMap()) {
if (source === null || typeof source !== 'object') {
return source;
}
if (source instanceof Date) {
return new Date(source);
}
if (source instanceof RegExp) {
return new RegExp(source);
}
@ahonn
ahonn / JavScript new.js
Last active September 25, 2019 10:09
implement the `new` keyword
function myNew(constructor, ...args) {
const self = {};
self.__proto__ = constructor.prototype;
const obj = constructor.apply(self, args);
// 构造函数返回对象或者函数时,直接返回
if (typeof obj === 'object' || typeof obj === 'function') {
return obj;
}
return self;
}