This file contains hidden or 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
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let smallerSorted = quicksort [a | a <- xs, a <= x] | |
biggerSorted = quicksort [a | a <- xs, a > x] | |
in smallerSorted ++ [x] ++ biggerSorted |
This file contains hidden or 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
fetch(`/api/following/`, { | |
method: "POST", | |
headers:{ | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
followerUsername: loginName, | |
followingUsername: nowname | |
}) | |
}) |
This file contains hidden or 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.serializeObject = function() | |
{ | |
var o = {}; | |
var a = this.serializeArray(); | |
$.each(a, function() { | |
if (o[this.name] !== undefined) { | |
if (!o[this.name].push) { | |
o[this.name] = [o[this.name]]; | |
} | |
o[this.name].push(this.value || ''); |
This file contains hidden or 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
package com.pwxcoo.github.utils; | |
import javax.crypto.SecretKeyFactory; | |
import javax.crypto.spec.PBEKeySpec; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.SecureRandom; | |
import java.security.spec.InvalidKeySpecException; | |
import java.util.Arrays; | |
import java.util.Base64; | |
import java.util.Random; |
This file contains hidden or 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
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <stack> | |
#include <bitset> | |
#include <cstdlib> | |
#include <cmath> |
This file contains hidden or 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.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.atomic.AtomicInteger; | |
public class AtomicIntegerExample { | |
private AtomicInteger sycValue = new AtomicInteger(0); | |
private static final int MAX_SYC_VALUE = 3 * 10; |
This file contains hidden or 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
vector<int> inorderTraversal(TreeNode* root) { | |
stack<TreeNode*> st; | |
vector<int> res; | |
auto now = root; | |
while(!st.empty() || now) | |
{ | |
while(now) | |
{ | |
st.push(now); |
This file contains hidden or 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
/** | |
* Time: O(n) | |
* Space: O(1) | |
* 1. find list if exists cycle. | |
* 2. 0 -> a(cycle s) -> b(cycle met) -> c(cycle s(e)) | |
* slow = a + b + (b + c)n1, fast = a + b + (b + c)n2. | |
* slow * 2 = fast | |
* 2a + 2b + 2*n1*(b + c) = a + b + n2*(b + c) => a = (n2 - 2*n1) * (b + c) - b | |
* After meeting, so one start going from head and meanwhile slow start going, they will meet at cycle begin. | |
**/ |
This file contains hidden or 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
def newtonSqrt(n, eps=1e-8): | |
""" | |
- ASSUME | |
f(x) = x^2 - n | |
when f(x)=0, x will be the root of n. | |
- DEDUCE BY Taylor Series Formula | |
f(x) = f(x0) + (x - x0)f'(x0) | |
- WHEN f(x)=0 | |
x = x0 - f(x0)/f'(x0) | |
x will be closer to the root than x0 |