This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./App.css"; | |
import Markdown from "react-markdown"; | |
import remarkGfm from "remark-gfm"; | |
const markdown = `# 低碳建筑行业 | |
建筑业(Construction Business)指国民经济中从事建筑安装工程的勘察、设计、施工以及对原有建筑物进行维修活动的物质生产部门。按照国民经济行业分类目录,作为国民经济二十个分类行业的建筑业,由以下四个大类组成:房屋建筑业,土木工程建筑业,建筑安装业,建筑装饰、装修和其他建筑业。 | |
## 一、政策环境 | |
2023 年基建投资仍为拉动经济重要抓手,地产销售复苏、投 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(() => { |