Skip to content

Instantly share code, notes, and snippets.

@unixzii
unixzii / ForceEnablingXcodeLLM.md
Last active July 4, 2024 09:03
A guide to force enabling Xcode LLM feature on China-SKU Macs.

Introduction

Apple restricted the access to Xcode LLM (Predictive code completion) feature on China models of Mac. This guide provides a way to bypass that restriction. It's verified on macOS 15.0 Beta (24A5264n), but there is no guarentee that it will always work on later macOS versions.

Prerequisites

  • Xcode is installed and run at least once.
  • SIP debugging restrictions are disabled (via csrutil enable --without debug command in recovery mode).

Disclaimer

@marius-se
marius-se / Vector.swift
Last active May 29, 2024 02:40
Swift PGVector
import PostgresNIO
import Foundation
/// A vector of floats. This is a custom type mirroring the `vector` type from
/// [pgvector](https://github.com/pgvector/pgvector/).
struct Vector: Codable {
/// The vector's values.
let value: [Float]
/// Creates a new `Vector`.
@lexrus
lexrus / ForkWeeklyReport.sh
Last active November 28, 2023 09:58
Fork custom command which export weekly report of current git user.
cd $path
DATE=`date -v-6d +"%Y-%m-%d"`
AUTHOR=`git config user.name`
LOG=`git log --branches --pretty=format:"\n%ad: %s" --date=short --after=$DATE --author="$AUTHOR"`
CHANGES=`git log --branches --date=short --after=$DATE --author="$AUTHOR" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "本周贡献代码: +%s行, -%s行, 总行数: %s\n", add, subs, loc }' -`
WEEKSTART=`date -v"monday" +"%-m月%d"`
TODAY=`date +"%-m月%d"`
REPORT="【周报】$WEEKSTART ~ $TODAY \n\n$CHANGES\n$LOG\n"
import SwiftUI
import PlaygroundSupport
struct ClickWheel: View {
var body: some View {
ZStack {
Circle()
.fill(LinearGradient(
gradient: Gradient(stops: [
.init(color: Color(#colorLiteral(red: 0.21568627655506134, green: 0.21568627655506134, blue: 0.21568627655506134, alpha: 1)), location: 0),
@ethanhuang13
ethanhuang13 / VirtualKeyboard.swift
Last active February 7, 2024 05:58
MacBook Air M1 Zhuyin Keyboard written with SwiftUI ~=300 LOC, < 4hrs
//
// VirtualKeyboard.swift
// MacBook Air M1 Zhuyin Keyboard
// Written with SwiftUI ~=300 LOC, < 4hrs
// Created by Ethan Huang on 2021/1/13.
// Twitter: @ethanhuang13
import SwiftUI
struct VirtualKeyboard: View {
@wogong
wogong / flomo.sh
Created December 13, 2020 17:07
flomo shell function
#!/bin/sh
fl () {
API="https://flomoapp.com/iwh/xxxxxxx/" # substitute with your flomo API
curl -s -H "Accept: application/json" -H "Content-type: application/json" -s -X POST $API -d '{"content":"'"$*"'"}'
}

WebAssembly 导学

提起 WebAssembly/Wasm 可能会想起它是一种可以在浏览器里运行 C/C++/Rust 的技术,实际上它是一个虚拟机标准,它的实现可以在 MCU(单片机)、移动设备、桌面电脑到服务器里面跑,可以嵌入到浏览器、嵌入到应用程序或者独立运行,没有具体的边界。

特点:

  1. 编译一次到处可运行(有点类似JVM虚拟机),源语言可以是 C/C++,Rust,Go,Swift ,TypeScript,C#,Kotlin 等等。
  2. 具体的功能依赖于导入的接口(Import API),否则只是一个单纯的运算器(栈式虚拟机)。目前接口主要有 Web JS 和 WASI 两种,前者用在浏览器里,后者可以作为独立应用程序(比如调用文件系统、socket 等)。
  3. 在 WASM 虚拟机里,只能调用宿主导入的方法和共享的内存,无法直接调用宿主的资源(比如 Web DOM 对象、文件系统等),所以天然具有沙盘安全特性。
  4. 性能很好,提供了接近本地程序的性能,同一段简单的 C 计算程序,以 WASM 方式运行大概慢 1 倍左右,相对一般动态语言慢几倍到上百倍来说,性能已非常突出。
@shaps80
shaps80 / SwiftUI-TextView.md
Last active May 6, 2023 22:17
A SwiftUI view that wraps a UITextView but provides almost all functionality though modifiers and attempts to closely match the Text/TextField components.
@waylybaye
waylybaye / index.js
Last active March 10, 2022 11:09
Send Notification using Telegram when new IAP is purchased
const functions = require('firebase-functions');
const TelegramBot = require('node-telegram-bot-api');
const token = "***"
const chatID = 1024 // your telegram id, you must first send a message to your bot
exports.notifyIAP = functions.analytics.event('in_app_purchase').onLog((event) => {
const purchaseValue = event.valueInUSD;
if (purchaseValue > 0) {
const bot = new TelegramBot(token, {polling: false});
@mayneyao
mayneyao / notion2blog.js
Last active July 4, 2024 17:35
Notion.so > Personal Blog | custom domain + disqus comment
const MY_DOMAIN = "agodrich.com"
const START_PAGE = "https://www.notion.so/gatsby-starter-notion-2c5e3d685aa341088d4cd8daca52fcc2"
const DISQUS_SHORTNAME = "agodrich"
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
const corsHeaders = {
"Access-Control-Allow-Origin": "*",