Skip to content

Instantly share code, notes, and snippets.

View laiso's full-sized avatar
☀️

laiso laiso

☀️
View GitHub Profile
@laiso
laiso / hono-llrt.js
Last active December 25, 2024 12:43
esbuild hono-llrt.js --outfile=bundle.mjs --platform=node --target=es2020 --format=esm --bundle
import { createServer } from 'net'
import { Hono } from 'hono'
// import { Hono } from './dist'
const PORT = 3000
/**
* TODO: Remove globalThis.Response
* The Response object is normally supported by the runtime.
* This is a workaround for the issue where `new Response` is not
@laiso
laiso / sponsor.py
Created January 21, 2024 13:26
How to check if a specific GitHub user is sponsoring me
import os
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
token = os.getenv("GITHUB_TOKEN")
transport = RequestsHTTPTransport(
url="https://api.github.com/graphql",
use_json=True,
headers={"Authorization": f"bearer {token}"},
@laiso
laiso / getCompletionsCycling.mjs
Created December 18, 2023 17:04
Retrieve completion suggestions from GitHub Copilot programmatically in a Node.js program
import path from "node:path";
import fs from "node:fs";
import { spawn } from "node:child_process";
/**
* $ node getCompletionsCycling.mjs ./sample.ts
*/
const server = spawn("node", ["./copilot.vim/dist/agent.js"]); // https://github.com/github/copilot.vim
@laiso
laiso / main.py
Last active June 14, 2023 14:09
ダジャレを送ると採点と評価をしてくれるプログラム https://zenn.dev/laiso/articles/b516dc215a2e87
import sys
import openai
import json
def run_conversation(input):
content = f"""
ダジャレの面白さをAからEに評価して、評価の理由を論理的にコメントします。
ダジャレ:{input}
@laiso
laiso / ExampleUnitTest.kt
Created May 21, 2023 08:43
Chat completetion streaming with openai-kotlin in unite test
package com.example.openaikotlintest
import com.aallam.openai.api.BetaOpenAI
import com.aallam.openai.api.chat.ChatCompletionRequest
import com.aallam.openai.api.chat.ChatMessage
import com.aallam.openai.api.chat.ChatRole
import com.aallam.openai.api.http.Timeout
import com.aallam.openai.api.model.ModelId
import com.aallam.openai.client.OpenAI
import com.aallam.openai.client.OpenAIConfig
import { connect } from 'cloudflare:sockets';
export default {
async fetch(req, env) {
const socket = connect({
hostname: 'neverssl.com',
port: 80
});
const writer = socket.writable.getWriter()
@laiso
laiso / semantic-kernel.py
Created April 22, 2023 12:23
Semantic Kernel Python Sample
import asyncio
import uuid
import semantic_kernel as sk
import semantic_kernel.ai.open_ai as sk_oai
KV = {} # DBのかわり
@laiso
laiso / console.js
Last active April 19, 2023 03:21
Batch follow from Twitter List https://twitter.com/i/lists/{id}/members
// Step 1
let nodes = Array.from(document.querySelectorAll('span span:not(:empty)')).filter(d => d.textContent != 'Remove');
for (const node of nodes) {
node.dispatchEvent( new MouseEvent('mouseover', {
bubbles: true,
cancelable: true,
view: window
}));
}
@laiso
laiso / post.ts
Last active July 30, 2022 15:20
Read a parameter from POST body in Vercel Edge Functions
// api/post.ts
export const config = {
runtime: 'experimental-edge',
}
export default async (req: Request) => {
if (req.method !== 'POST') {
return new Response('Method not allowed', { status: 405 });
}
@laiso
laiso / CodePiece.js
Last active November 5, 2020 16:21
SSG+CSR #CodePiece
// pages/posts/[id].js
export default function Page(props) {
const router = useRouter()
const [post, setPost] = useState(props.post)
if (!post) {
return <Locading />
}
useEffect(async () => {
if (!post) {
const resp = fetch(`https://example.com/api/post/${router.params.id}`)