Skip to content

Instantly share code, notes, and snippets.

@ambar
ambar / 0.README.md
Last active March 23, 2024 04:31
Copilot Pair Programming

Copilot

品牌

  • GH Copilot
    • Copilot Chat (Editor/Github.com)
    • Copilot in the CLI
    • Copilot Enterprise (Github.com 聊天/PR 摘要)
  • MS Copilot
    • Bing Chat -> Copilot
@ambar
ambar / react.js
Last active December 13, 2024 04:14
jupyter deno react
import React from 'npm:react';
import ReactDOM from 'npm:react-dom/server';
// https://docs.jupyter.org/en/latest/reference/mimetype.html
const inspect = (obj: any) => {
if (React.isValidElement(obj)) {
return {
[Symbol.for('Jupyter.display')]() {
return {
'text/html': ReactDOM.renderToString(obj),
/**
* 将 CacheStorage 转换为简单的 key/value 存储
*/
export const createStore = (name: string) => {
const cacheP = caches.open(name)
const encodeKey = (str: string) => `/?key=${encodeURIComponent(str)}`
const decodeKey = (str: string) => str.match(/key=([^;]+)/)?.[1] || ''
async function get(key: string) {
const cache = await cacheP
@ambar
ambar / about.md
Last active January 29, 2021 16:48
deep merge

Comparison

name immutable concat dedupe clone multiple parameters recommended
merge-deep@3.0.2 true true true true yes yes
deepmerge@3.0.0 true true false false(option) no
lodash/mege false false false true yes
lodash/megeWith false false false true yes yes
const iconv = require('iconv-lite')
const querystring = require('querystring')
const parseGBKQueryString = string => {
return querystring.parse(string, null, null, {
decodeURIComponent: v => {
return iconv.decode(Array.from(unescape(v)).map(c => c.codePointAt()), 'gbk')
}
})
}
@ambar
ambar / aes.js
Last active February 7, 2018 11:10
web crypto for AES-CBC
const atos = a =>
Array.from(a)
.map(c => String.fromCodePoint(c))
.join('')
const stoa = s => Array.from(s).map(c => c.codePointAt())
const createAes = (keyString, ivString) => {
const keyUtf8 = new TextEncoder().encode(keyString)
const ivUtf8 = new TextEncoder().encode(ivString)
@ambar
ambar / FractionalBorder.css
Last active February 6, 2017 08:21
fractional border
:root {
/* 顶部极细边框(白色背景使用) */
--topLightFractionalBorder {
border-top: 1px solid #eee;
border-image-source: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect width='1' height='.5' fill='#eee'/></svg>");
border-image-slice: 1 0 0;
}
/* 底部极细边框(白色背景使用) */
--bottomLightFractionalBorder {
@ambar
ambar / babel.sh
Last active November 30, 2015 07:28
source map bug:`serve -p 3000`
cp ./foo.es ./foo.js
babel ./foo.js --preset es2015 --source-maps inline -o ./foo.js
@mixin with-hash-padding($padding: 200px) {
&:before {
display: block;
content: " ";
margin-top: -$padding;
height: $padding;
visibility: hidden;
}
}
@ambar
ambar / schedules.json
Created June 1, 2014 04:45
2014 FIFA World Cup Schedule
[
{
"date": "2014-06-12",
"matches": [
{
"localDatetime": "12 Jun 2014 - 17:00",
"matchnum": "Match 1",
"group": "Group A",
"location": {
"stadium": "Arena de Sao Paulo",