Skip to content

Instantly share code, notes, and snippets.

import inspect
from functools import wraps
import openai
def generate_code(signature, docstring):
init_prompt = "You are a Python expert who can implement the given function."
definition = f"def {signature}"
prompt = f"Read this incomplete Python code:\n```python\n{definition}\n```"

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 倍左右,相对一般动态语言慢几倍到上百倍来说,性能已非常突出。
const marky = require('marky')
const render = Vue.prototype._render
const update = Vue.prototype._update
const camelize = str => str && Vue.util.camelize(str)
function getName (vm) {
if (!vm.$parent) return 'root'
return (
camelize(vm.$options.name) ||
camelize(vm.$options._componentTag) ||
from sre_parse import Pattern, SubPattern, parse as sre_parse
from sre_compile import compile as sre_compile
from sre_constants import BRANCH, SUBPATTERN
class Scanner(object):
def __init__(self, tokens, flags=0):
subpatterns = []
pat = Pattern()
@tonyseek
tonyseek / Usage.md
Created August 22, 2015 12:27
QRCode generator in Flask.

How to use

from flask import Flask, render_template
from myapp.views.qrcode import bp, make_qrcode_url


app = Flask(__name__)
app.config['SECRET_KEY'] = 'random-bytes'
app.register_blueprint(bp)
@lexrus
lexrus / Deliverfile.rb
Created April 3, 2015 08:57
Universal Change Log
changelog({
"cmn-Hans" => "感谢使用 VPN On!为改善用户使用体验,我们每隔一周就会在 App Store 更新应用。你可以前往手机“设置”>“iTunes 与 App Store”>“自动下载的项目”,打开“更新”。\n\nVPN On 应用的每次更新都会改进速度和稳定性。一有新功能推出,我们会在应用中提示你。",
"cmn-Hant" => "感謝使用 VPN On!爲改善用戶使用體驗,我們每隔一週就會在 App Store 更新應用。你可以前往手機“設置”>“iTunes 與 App Store”>“自動下載的項目”,打開“更新”。\n\nVPN On 應用的每次更新都會改進速度和穩定性。一有新功能推出,我們會在應用中提示你。",
"ja-JP" => "VPN Onをご利用いただきありがとうございます。VPN Onではアプリをより快適にご利用いただくため、アプリストアで隔週でアップデートを行っております。[設定] > [iTunes & App Store] > [自動ダウンロード]でアップデートをオンにすることで、自動的に(このページにアクセスすることなく)アプリをアップデートいただけます。 \n\nVPN Onアプリのアップデートではスピードと信頼性の向上が行われており、また新しい機能が追加されると、アプリ内でその機能がハイライトされます。",
"it-IT" => "Grazie di usare VPN On! Per migliorare la nostra applicazione, pubblichiamo aggiornamenti nell'App Store ogni 2 settimane. Puoi aggiornare l'applicazione automaticamente (senza dover tornare qui) accedendo a Impostazioni > iTunes Store e App Store > Download automatici e attivando Aggiornamenti. \n\nOgni aggiornamento della nostra applicazione VPN On presenta miglioramenti relativi a velocità e aff
@rpplusplus
rpplusplus / appDelegate
Last active August 29, 2015 14:11
Hello World
#import <objc/runtime.h>
#import <objc/message.h>
@implementation AppDelegate
id (*my_msgSend)(id, SEL, ...) = (void *)objc_msgSend;
void (*my_msgSend_)(id, SEL, ...) = (void *)objc_msgSend;;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@bsweger
bsweger / useful_pandas_snippets.md
Last active March 20, 2024 21:09
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@staltz
staltz / introrx.md
Last active March 26, 2024 00:52
The introduction to Reactive Programming you've been missing
@OliverLetterer
OliverLetterer / XCDUUID.m
Created January 26, 2013 17:05
With this gist, I, as a total assembly noob, am trying to understand the XCDUUID runtime hack (https://github.com/0xced/NSUUID/blob/1.0.1/NSUUID.m#L167-L221) to be able to use NSUUID on iOS < 6.0.
@implementation XCDUUID
+ (void) load
{
// query runtime if NSUUID class already exists, if so => done
if (objc_getClass("NSUUID"))
{
return;
}