Skip to content

Instantly share code, notes, and snippets.

@a9
a9 / index.ts
Created August 20, 2024 01:09 — forked from rishi-raj-jain/index.ts
Google OAuth 2.0 on the Edge with Hono and Cloudflare Workers
// Do enable nodejs_compat
// https://developers.cloudflare.com/workers/runtime-apis/nodejs/
import crypto from 'node:crypto'
import { Context, Hono } from 'hono'
const app = new Hono()
function generateJWT(payload, secret, expiresIn) {
const header = { alg: 'HS256', typ: 'JWT' }
const encodedHeader = base64UrlEncode(JSON.stringify(header))
@a9
a9 / testRegex.js
Created August 16, 2024 04:47 — forked from hanxiao/testRegex.js
Regex for chunking by using all semantic cues
// Updated: Aug. 15, 2024
// Run: node testRegex.js testText.txt
// Used in https://jina.ai/tokenizer
const fs = require('fs');
const util = require('util');
// Define variables for magic numbers
const MAX_HEADING_LENGTH = 7;
const MAX_HEADING_CONTENT_LENGTH = 200;
const MAX_HEADING_UNDERLINE_LENGTH = 200;
@a9
a9 / trial.key
Created June 25, 2021 09:24 — forked from huqi/trial.key
Beyond Compare 4 license for Mac
Beyond Compare 4
Licensed to: ASIO Allsoftinone
Quantity: 1 user
Serial number: 1822-9597
License type: Pro Edition for Windows
--- BEGIN LICENSE KEY ---
H1bJTd2SauPv5Garuaq0Ig43uqq5NJOEw94wxdZTpU-pFB9GmyPk677gJ
vC1Ro6sbAvKR4pVwtxdCfuoZDb6hJ5bVQKqlfihJfSYZt-xVrVU27+0Ja
hFbqTmYskatMTgPyjvv99CF2Te8ec+Ys2SPxyZAF0YwOCNOWmsyqN5y9t
@a9
a9 / appendBlur.swift
Created February 18, 2020 11:19 — forked from 0xWDG/appendBlur.swift
Append Blur to a NSView, NSButton, NSTextField
//
// appendBlur.swift
//
// Created by Wesley de Groot on 09-07-16.
// Copyright © 2016 Wesley de Groot. All rights reserved.
//
import Foundation
enum blur: String {
case light = "light"
@a9
a9 / chrome-dark.css
Created June 16, 2019 02:37
chrome prefers-color-scheme dark
@media (prefers-color-scheme: dark) {
body {
color: white;
background-color: black;
}
}
@a9
a9 / vue-typescript-component.vue
Last active May 30, 2019 13:59
Vue Typescript Component File Template as WebStorm #vue
#set( $ClassName = "${Prefix}-${NAME}" )
#set( $ComponentNamePrefix = ${StringUtils.removeAndHump(${Prefix}, "-")} )
#set( $ComponentName = ${StringUtils.removeAndHump(${NAME}, "-")} )
<template>
<div class="${ClassName}">#[[$END$]]#</div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
@a9
a9 / effective-graphql-and-antd.md
Created September 12, 2018 07:41
Effective GraphQL + Antd

高效的 GraphQL + Antd

本文原载于我的独立博客 https://lutaonan.com/blog/effective-graphql-and-antd/

在过去的几年,不论是面向内部的系统,还是面向外部的产品,我们都大量地使用了 Ant.Design —— 一个基于 React 的 UI 组件库。

在做内部系统时,Ant.Design 解决了几乎 60% 的问题。剩下的问题在业务逻辑和代码组织的复杂度。我见过很多内部系统因为滥用状态管理而使代码变得复杂,他们之所以使用状态管理库,并不是因为应用的状态复杂,而是因为需要一个状态树来管理网络请求的状态、接口返回的数据等等这些和接口相关的状态。

真的需要状态管理库吗?在之前,我没有信心回答这个问题。但在使用了 GraphQL (Apollo) 后,我确信,在大多数场景,你不再需要状态管理。

@a9
a9 / compress.go
Created May 11, 2018 06:13 — forked from iamralch/compress.go
ZIP archives in Golang
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
)
func zipit(source, target string) error {
zipfile, err := os.Create(target)
@a9
a9 / CreateJob.sh
Created April 24, 2018 08:35 — forked from stuart-warren/CreateJob.sh
Create a job in Jenkins (or folder) using the HTTP API
# check if job exists
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken
# with folder plugin
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# without folder plugin
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# create folder
@a9
a9 / nginx.conf
Created July 25, 2017 15:59 — forked from micho/nginx.conf
nginx config for http/https proxy to localhost:3000
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf: