Skip to content

Instantly share code, notes, and snippets.

View ChenZhongPu's full-sized avatar

zhongpu ChenZhongPu

  • Southwestern University of Finance and Economics
  • Chengdu
View GitHub Profile
@ChenZhongPu
ChenZhongPu / App.js
Last active November 26, 2023 02:22
gpt stream
import "./App.css";
import React, { useState, useEffect } from "react";
import Markdown from "react-markdown";
import remarkGfm from "remark-gfm";
function App() {
const [typingText, setTypingText] = useState("");
useEffect(() => {
@ChenZhongPu
ChenZhongPu / bing_img.py
Created November 15, 2023 02:22
获取Bing图片
import requests
from bs4 import BeautifulSoup
def get_img(keyword):
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
}
url = f"https://cn.bing.com/images/search?q={keyword}"
html = requests.get(url, headers=headers).text
@ChenZhongPu
ChenZhongPu / App.js
Last active November 11, 2023 09:20
测试Markdown
import "./App.css";
import Markdown from "react-markdown";
import remarkGfm from "remark-gfm";
const markdown = `# 低碳建筑行业
建筑业(Construction Business)指国民经济中从事建筑安装工程的勘察、设计、施工以及对原有建筑物进行维修活动的物质生产部门。按照国民经济行业分类目录,作为国民经济二十个分类行业的建筑业,由以下四个大类组成:房屋建筑业,土木工程建筑业,建筑安装业,建筑装饰、装修和其他建筑业。
## 一、政策环境
2023 年基建投资仍为拉动经济重要抓手,地产销售复苏、投
@ChenZhongPu
ChenZhongPu / perf.c
Last active September 2, 2023 01:45
blogs-2023-09
// simple code to benchmark the sort
long time_it(void (*f)(int *, int), int *arr, int n) {
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
f(arr, n);
clock_gettime(CLOCK_MONOTONIC, &end);
long diff = (end.tv_sec - start.tv_sec) * 1e9;
diff += (end.tv_nsec - start.tv_nsec);
return diff;
}
@ChenZhongPu
ChenZhongPu / avx-dot.c
Last active April 19, 2023 09:39
SIMD Demo
float avx_dot_product(float *a, float *b, int n) {
__m256 sum = _mm256_setzero_ps(); // set sum to 0
for (int i = 0; i < n; i += 8) {
__m256 a_vals = _mm256_loadu_ps(a + i); // load 8 floats from a
__m256 b_vals = _mm256_loadu_ps(b + i); // load 8 floats from b
sum =
_mm256_add_ps(sum, _mm256_mul_ps(a_vals, b_vals)); // sum += a[i] * b[i]
}
__m128 low = _mm256_castps256_ps128(sum);
@ChenZhongPu
ChenZhongPu / wifi.sh
Last active February 14, 2023 07:16
Shell to list all connected devices of a hotspot
wifiInterface=$(iw dev | grep Interface | awk '{print $2}')
ssid=$(iw dev $wifiInterface info | grep ssid | awk '{print $2}')
echo "Your SSID is $ssid."
connections=$(ip neigh | grep $wifiInterface)
ips=()
macs=()
devices=()
while IFS= read -r conn;
do
@ChenZhongPu
ChenZhongPu / BoxText.java
Created June 15, 2021 08:04
Autoboxing Test
import java.time.Duration;
import java.time.Instant;
public class BoxTest {
private static long sum1() {
long sum = 0L;
for (long i = 0; i < Integer.MAX_VALUE; i++) {
sum += i;
}
return sum;
@ChenZhongPu
ChenZhongPu / bi_dij.rs
Last active September 21, 2019 06:42
Bidirectional Dijkstra Algorithm in Rust
fn bi_dij(&self, reverse_graph: &Graph2, start: usize, end: usize) -> Option<f64> {
let mut fwd_dists = vec![std::f64::MAX; self.adj_list.len()];
let mut fwd_visited = vec![false; self.adj_list.len()];
let mut rev_dists = vec![std::f64::MAX; self.adj_list.len()];
let mut rev_visited = vec![false; self.adj_list.len()];
let mut fwd_heap = BinaryHeap::new();
fwd_heap.push(State {node: start, dist: 0.0});
import java.util.concurrent._
import scala.util.DynamicVariable
package object common {
val forkJoinPool = new ForkJoinPool
abstract class TaskScheduler {
def schedule[T](body: => T): ForkJoinTask[T]
@ChenZhongPu
ChenZhongPu / multiValuesDic.py
Created August 19, 2015 12:37
Mapping Keys to Multiple Values in a Dictionary
"""
If you want to map keys to multiple values, you need to store the multiple values in another container, like a list or set.
For example:
d = {
'a': [1, 2, 3],
'b': [4, 5]
}
"""
from collections import defaultdict