Skip to content

Instantly share code, notes, and snippets.

View beiweiqiang's full-sized avatar
🎯
Focusing

beiweiqiang beiweiqiang

🎯
Focusing
  • Guangzhou, China
View GitHub Profile
@beiweiqiang
beiweiqiang / Insertion.java
Created July 8, 2019 00:59
Java 插入排序
public class Insertion {
public static void sort(Comparable[] a) {
int N = a.length;
// 从第二个元素开始操作
for (int i = 1; i < N; i++) {
// 索引之前的所有元素, 从右往左, 一个个进行比较, 如果后一个比前一个小, 则交换相邻的两个元素
for (int j = i; j > 0 && less(a[j], a[j - 1]); j--) {
exch(a, j, j-1);
}
}
@beiweiqiang
beiweiqiang / Section.java
Last active July 7, 2019 00:06
java 选择排序
public class Selection {
public static void sort(Comparable[] a) {
int N = a.length;
for (int i = 0; i < N; i++) {
int min = i;
for (int j = i + 1; j < N; j++) {
if (less(a[j], a[min])) {
min = j;
}
}
@beiweiqiang
beiweiqiang / app2.js
Created March 13, 2019 00:25
defer 脚本总是按照指定它们的顺序进行执行
console.log('app2.js: 1 -> -> ', 'apps');
@beiweiqiang
beiweiqiang / index.html
Created March 10, 2019 03:27
document 上的 DOMContentLoaded 事件 / window 上的 load 事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
document.addEventListener('DOMContentLoaded', function (event) {
console.log('index.html: 9 -> -> ', 'dom');
console.log('index.html: 10 -> -> ', document.getElementById('img').offsetWidth);
@beiweiqiang
beiweiqiang / index.html
Last active March 10, 2019 03:26
defer's script 的执行时机
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
document.addEventListener('DOMContentLoaded', function (event) {
console.log('index.html: 9 -> -> ', 'dom');
console.log('index.html: 10 -> -> ', document.getElementById('img').offsetWidth);
@beiweiqiang
beiweiqiang / index.html
Last active March 10, 2019 03:28
纯前端, 解析 json 为 csv 文件并触发 csv 下载
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<h1>This page does nothing....</h1>
@beiweiqiang
beiweiqiang / app.js
Created January 19, 2019 00:14
Digest Access Authentication using Nodejs
const http = require('http');
const crypto = require('crypto');
const realm = 'user';
const ACCOUNT = {
'username': 'psw'
};
class Nonce {
constructor() {
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 09:34
merge sort AND bubble sort
# Sorting
# Implement two types of sorting algorithms:
# Merge sort and bubble sort.
import math
from random import randint
def merge_arr(arr1, arr2):
"""
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 08:17
Fast Exponentiation
# Fast Exponentiation
# Ask the user to enter 2 integers a and b and output a^b (i.e. pow(a,b)) in O(lg n) time complexity.
def my_pow(a, b):
if b == 0: return 1
temp = my_pow(a, b // 2)
if b % 2 == 0:
return temp * temp
else:
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 07:07
Find Next Prime Number
# Next Prime Number
# Have the program find prime numbers until the user chooses to stop asking for the next one.
# 找到下一个质数
prime_number = [2]
i = 0
def find_next_prime():
global i