Skip to content

Instantly share code, notes, and snippets.

View longluo's full-sized avatar
💭
I may be slow to respond.

Frank Luo longluo

💭
I may be slow to respond.
View GitHub Profile
@longluo
longluo / write_wav_file.c
Created January 16, 2024 01:41
write wav file in C
#include <string.h>
#include <stdio.h>
#include <math.h>
struct wav_header
{
char riff[4]; /* "RIFF" /
int32_t flength; / file length in bytes /
char wave[4]; / "WAVE" /

无用知识的有用性

弗莱克斯纳

[按] 30年代美国普林斯顿大学校长亚伯拉罕·弗莱克斯纳(Abraham Flexner)教授曾以 “无用知识的有用性”为题,发表过一篇在科学界有影响的文章。该文章强调了基础研 究以及自由探索的重要性。全文一万余字,现节译如下,以餐读者。

  智力与精神生活在表面上是一种无用型活动。人们之所以大量从事这种活动,是因

@longluo
longluo / 投资.md
Last active June 18, 2022 01:58
Investment 投资知识

Stock-ETF-And-Bonddata

title date mathjax comments tags categories keywords
Math and Physics Intuitions
2022-03-26 11:49:38 -0700
true
true
Math
Physics
Intuition
Math
Math, Physics, CS, 数学, 物理, 几何, Intuition,
@longluo
longluo / html.md
Last active June 15, 2022 03:13
HTML 常用代码

1x1px 透明 gif 的 base64 代码

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=">
@longluo
longluo / gcd.java
Last active June 14, 2022 03:26
GCD 最大公约数(greatest common divisor)
// GCD Recursion
public int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
// GCD Iteration
public int gcd_iter(int a, int b) {
int remain = 1;
while (remain != 0) {
remain = a % b;
@longluo
longluo / Newton.java
Last active June 14, 2022 06:11
Newton 牛顿迭代法求根
// 牛顿迭代法求某个数平方根
// Newton
public static int mySqrt_newton(int x) {
if (x == 0) {
return 0;
}
double C = x;
double x0 = x;
while (true) {
@longluo
longluo / BitManipulation.java
Last active June 14, 2022 06:08
Bit Manipulation 位运算
/**
* The Lower 1 of the bits.
* @param num
* @return
*/
public static int lowBit(int num) {
return num & (-num);
}
@longluo
longluo / KMP.java
Last active June 15, 2022 03:32
KMP 字符串匹配算法
// KMP time: O(n+m) space: O(m)
public int KMP(String haystack, String needle) {
if (needle == null || needle.length() == 0) {
return 0;
}
int sLen = haystack.length();
int pLen = needle.length();
int[] next = new int[pLen];
@longluo
longluo / Regex 常用正则表达式.md
Last active June 15, 2022 03:59
Regex 常用正则表达式

常用正则表达式

一、校验数字的表达式

  1. 数字:^[0-9]*$

  2. n位的数字:^\d{n}$

  3. 至少n位的数字:^\d{n,}$