跳到主要内容

· 阅读需 1 分钟

今天在开发android,在开发过程中在思考一个问题,如果是从0开始,并没有完善的基建,那么如何知晓接口返回的情况那,于是打算重新熟悉charles进行抓包

安装charles

https://www.charlesproxy.com/download/latest-release/

设置代理

  • 点击proxy-> proxy setting来创建代理端口,点击enable transparent http proxying
  • 点击proxy-> ssl proxy setting来容许所有流量流入

下载根证书到android手机

  • 查看根证书在本地的位置,并导出证书为cer文件

  • 将cer文件转化为pem文件

openssl x509 -inform der -in android.cer -out android.pem
  • 将pem文件传输到手机
adb push android.pem /sdcard/
  • 安装证书

接着就可以开始抓包了。

· 阅读需 2 分钟

问题

最近在开发的时候遇到一个难题,就是墙的问题,有一个场景就是我把请求发送到 openai 的时候会被墙了,然后这个时候无需要使用魔法解决,但是魔法也不是万能的,也经常会被墙,所以这个时候如果有一个问题定的解决方案是非常好的,而自己维护的无论是代理还是魔法,必然在可靠性和性能侧有一些问题,那么如何解决这个问题那?

解决

  • cloudflare

cloudflare最近提供了一个AIgateway的服务,因为cloudflare在国内是有服务的,所以使用AIgateway能够做到高性能访问openai。比自己维护的无论在稳定性和性能侧面要好的多,真是一个宝藏选择。

文档

AI gateway

· 阅读需 1 分钟

终端代理

ss
export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

常用命令

  1. 设置镜像源
淘宝: npm config set registry https://registry.npm.taobao.org

npm官方: npm config set registry https://registry.npmjs.org/

yarn: yarn config set registry https://registry.npm.taobao.org

pip:
# 修改 ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

docker:
# 修改 /etc/docker/daemon.json
{
"registry-mirrors": ["https://your-mirror.com"]
}
  1. 常用brew命令
// 包信息
brew info nginx
// 重启服务
brew services restart nginx
// 服务信息
brew services info nginx
  1. mac修改hosts
// 编辑hosts
sudo vim /etc/hosts
// 添加网址
127.0.0.1 example.com
// 刷新 DNS 缓存
sudo dscacheutil -flushcache

· 阅读需 1 分钟

介绍

开发提效终极工具。

可以集成平台

  • vscode
  • jetbrain家族

使用技巧

· 阅读需 1 分钟

前置条件

阿里云容器仓库

使用github action将镜像打包上传至阿里云容器仓库

name: Docker Build and Push to Aliyun

on:
push:
tags:
- 'v*' # 当推送符合 'v*' 格式的标签时触发

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Login to Aliyun Container Registry
run: |
echo "${{ secrets.ALIYUN_CONTAINER_REGISTRY_PASSWORD }}" | docker login --username ${{ secrets.ALIYUN_CONTAINER_REGISTRY_USERNAME }} --password-stdin registry.cn-shanghai.aliyuncs.com

- name: Extract Git Tag for Version
id: tag
run: echo "::set-output name=version::$(git describe --tags --abbrev=0)"

- name: Build Docker Image
run: |
docker build --platform linux/amd64 -t registry.cn-shanghai.aliyuncs.com/${{ secrets.ALIYUN_CONTAINER_REGISTRY_NAMESPACE }}/yiwen-blog-website:${{ steps.tag.outputs.version }} .

- name: Push to Aliyun Container Registry
run: |
docker push registry.cn-shanghai.aliyuncs.com/${{ secrets.ALIYUN_CONTAINER_REGISTRY_NAMESPACE }}/yiwen-blog-website:${{ steps.tag.outputs.version }}

说明:

  • 容器版本使用tag标签版本来动态定义,而不是写死
  • 设置对应的秘钥,在代码变化的时候手动push到容器仓库

· 阅读需 1 分钟
信息

20230923是非常有意义的一天,因为这一天我终于知道原来mac也可以VMare Fusion有个人免费版本。

安装VMare Fusion player

VMare Funsion player

虚拟机安装

阿里centos9镜像 选择最新的就可以

常见插件配置

  1. 镜像自带gedit,但是为了使用便利性,建议安装zshoh-my-zsh,以及zsh-autosuggestionszsh-syntax-highlighting
  2. 必备:dockergit

· 阅读需 1 分钟

周六加班的时候同事有推荐使用fork进行代码管理,因为fork用起来不卡,而且有git cherry-picker功能。今天尝试了一下,确实还行。

百度网盘有破解版本。

· 阅读需 3 分钟

前置条件

  1. Docusaurus: 2.4.1
  2. @giscus/react: 2.3.0

开通 giscus

giscus官网

备注
  1. 公共仓库
  2. 开启discussions
  3. 下载giscus app

封装 Comment

  1. 安装 @giscus/react
npm i @giscus/react
  1. 封装 Comment
Comment.tsx
import React from 'react';
import Giscus from '@giscus/react';

export const Comment = () => {
return (
<div style={{ paddingTop: 50 }}>
<Giscus
id="comments"
// highlight-warn-start
// 这部分填写你自己的
repo="3Alan/site"
repoId=""
category="Announcements"
categoryId=""
// highlight-warn-end
mapping="title"
strict="1"
term="Welcome to @giscus/react component!"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="bottom"
theme="dark_dimmed"
lang="zh-CN"
loading="lazy"
/>
</div>
);
};

export default Comment;

Swizzling Docusaurus

Swizzling 文档页面

yarn run swizzle @docusaurus/theme-classic DocItem/Layout -- --eject --typescript
src/theme/DocItem/Layout/index.tsx
import React from 'react';
import clsx from 'clsx';
import { useWindowSize } from '@docusaurus/theme-common';
// @ts-ignore
import { useDoc } from '@docusaurus/theme-common/internal';
import DocItemPaginator from '@theme/DocItem/Paginator';
import DocVersionBanner from '@theme/DocVersionBanner';
import DocVersionBadge from '@theme/DocVersionBadge';
import DocItemFooter from '@theme/DocItem/Footer';
import DocItemTOCMobile from '@theme/DocItem/TOC/Mobile';
import DocItemTOCDesktop from '@theme/DocItem/TOC/Desktop';
import DocItemContent from '@theme/DocItem/Content';
import DocBreadcrumbs from '@theme/DocBreadcrumbs';
import type { Props } from '@theme/DocItem/Layout';

import styles from './styles.module.css';
// highlight-add-line
import Comment from '../../../components/comment';
/**
* Decide if the toc should be rendered, on mobile or desktop viewports
*/
function useDocTOC() {
const { frontMatter, toc } = useDoc();
const windowSize = useWindowSize();

const hidden = frontMatter.hide_table_of_contents;
const canRender = !hidden && toc.length > 0;

const mobile = canRender ? <DocItemTOCMobile /> : undefined;

const desktop =
canRender && (windowSize === 'desktop' || windowSize === 'ssr') ? (
<DocItemTOCDesktop />
) : undefined;

return {
hidden,
mobile,
desktop,
};
}

export default function DocItemLayout({ children }: Props): JSX.Element {
const docTOC = useDocTOC();
return (
<div className="row">
<div className={clsx('col', !docTOC.hidden && styles.docItemCol)}>
<DocVersionBanner />
<div className={styles.docItemContainer}>
<article>
<DocBreadcrumbs />
<DocVersionBadge />
{docTOC.mobile}
<DocItemContent>{children}</DocItemContent>
<DocItemFooter />
</article>
<DocItemPaginator />
</div>
// highlight-add-line
<Comment />
</div>
{docTOC.desktop && (
<div className="col col--3">{docTOC.desktop}</div>
)}
</div>
);
}

Swizzling 博客页面

yarn run swizzle @docusaurus/theme-classic BlogPostPage -- --eject --typescript
src/theme/BlogPostPage/index.tsx
import React, { type ReactNode } from 'react';
import clsx from 'clsx';
import {
HtmlClassNameProvider,
ThemeClassNames,
} from '@docusaurus/theme-common';

import {
BlogPostProvider,
useBlogPost,
// @ts-ignore
} from '@docusaurus/theme-common/internal';
import BlogLayout from '@theme/BlogLayout';
import BlogPostItem from '@theme/BlogPostItem';
import BlogPostPaginator from '@theme/BlogPostPaginator';
import BlogPostPageMetadata from '@theme/BlogPostPage/Metadata';
import TOC from '@theme/TOC';
import type { Props } from '@theme/BlogPostPage';
import type { BlogSidebar } from '@docusaurus/plugin-content-blog';
// highlight-add-line
import Comment from '../../components/comment';

function BlogPostPageContent({
sidebar,
children,
}: {
sidebar: BlogSidebar;
children: ReactNode;
}): JSX.Element {
const { metadata, toc } = useBlogPost();
const { nextItem, prevItem, frontMatter } = metadata;
const {
hide_table_of_contents: hideTableOfContents,
toc_min_heading_level: tocMinHeadingLevel,
toc_max_heading_level: tocMaxHeadingLevel,
} = frontMatter;
return (
<BlogLayout
sidebar={sidebar}
toc={
!hideTableOfContents && toc.length > 0 ? (
<TOC
toc={toc}
minHeadingLevel={tocMinHeadingLevel}
maxHeadingLevel={tocMaxHeadingLevel}
/>
) : undefined
}
>
<BlogPostItem>{children}</BlogPostItem>
{(nextItem || prevItem) && (
<BlogPostPaginator nextItem={nextItem} prevItem={prevItem} />
)}
// highlight-add-line
<Comment />
</BlogLayout>
);
}

export default function BlogPostPage(props: Props): JSX.Element {
const BlogPostContent = props.content;
return (
<BlogPostProvider content={props.content} isBlogPostPage>
<HtmlClassNameProvider
className={clsx(
ThemeClassNames.wrapper.blogPages,
ThemeClassNames.page.blogPostPage
)}
>
<BlogPostPageMetadata />
<BlogPostPageContent sidebar={props.sidebar}>
<BlogPostContent />
</BlogPostPageContent>
</HtmlClassNameProvider>
</BlogPostProvider>
);
}

· 阅读需 5 分钟

问题

在最近的开发过程中碰到一个问题,每次拉取master分支开发完成后,会有其他人已经合并到master分支,这个时候我往往是通过merge来做,但是merge导致每次提交都会多出一条提交记录,在问题追溯的时候总是不太好。所以我想着如何解决这个问题

解决办法

拉取最新主分支
git fetch origin master
执行rebase
git rebase origin/master

git rebase介绍

  1. 工作方式:rebase 会重新应用一个分支上的更改到另一个分支。它首先找到两个分支的共同祖先,然后将改动的每个提交应用于目标分支。

  2. 提交历史:使用 rebase 会创建一个更线性的历史。它实际上是移动了一系列的提交到新的基线(base)。这会改变这些提交的哈希值,因为Git中的提交包括父提交的哈希值。

  3. 冲突解决:在 rebase 过程中遇到的冲突需要在每个重新应用的提交过程中逐个解决。这与 merge 不同,merge 是在最后创建合并提交之前一次性解决所有冲突。

  4. 适用场景:rebase 更适用于当你想要一个干净、线性的提交历史时。它常用于整理特性分支的提交历史,使其更加整洁和有序,然后再将这个特性分支合并到主分支。

Merge和Rebase比较

  1. 提交历史的清晰度:merge 保留了所有分支的历史和合并点,而 rebase 则提供了一个更线性、更干净的历史。

  2. 历史的改变:merge 保留了原始的提交哈希值和历史,而 rebase 会改变提交的哈希值(因为提交的上下文发生了改变)。

  3. 冲突解决的方式:rebase 可能需要在多个提交上反复解决相同的冲突,而 merge 则是一次性解决所有冲突。

  4. 最佳使用时机:如果你需要频繁地从一个长期存在的分支(如 main 或 develop)中获取最新的更改,rebase 是一个很好的选择,因为它避免了多余的合并提交。而 merge 更适合在最终整合长期分支时使用,因为它保留了分支之间的合并点和关系。

结论

merge 和 rebase 都是处理分支间差异的强大工具,选择使用哪一个取决于你的具体需求、团队规范以及你希望维护的历史类型。rebase 对于维持一个清洁、线性的历史非常有效,而 merge 则提供了一个直观、真实的开发历史视图。在协作的环境中,理解并正确使用这两种方法对于维护一个健康、可管理的代码库至关重要。

Rebase冲突

当您使用 rebase 将您的分支(例如,特性分支)放到 master 分支的最新提交之上时,如果 master 分支的最新提交修改了与您在特性分支中修改的相同的代码部分,就会出现冲突。

处理rebase冲突

  • 当出现冲突时,Git会暂停rebase操作。
  • 此时,你需要手动解决这些冲突。
  • 解决冲突后,使用git add将更改标记为已解决。
  • 然后,使用git rebase --continue继续rebase过程。
  • 如果你决定不继续rebase,可以使用git rebase --abort回到原始状态。
  • 记住,rebase是一个强大但复杂的工具。在处理共享分支时要特别小心,因为rebase会改变历史,可能会导致其他协作者的困惑或更多的合并冲突。

问题

不要在公共分支rebase

· 阅读需 1 分钟

cherry-pick 允许你选择一个或多个提交从其他分支拷贝到当前分支。它在以下场景中非常有用:

作用

  • 选择性合并:如果你只想将特定的提交从一个分支引入到当前分支,而不是整个分支的更改,cherry-pick 是完美的工具。
  • 修复和调整:在一些复杂的分支策略中,特定的修复可能只需要应用到某些分支上。cherry-pick 可以帮助你实现这一点,而无需进行完整的分支合并。

使用

使用fork应用来使用git cherry-pick体验极好,可以将commit从其他分支检出到自己分支。