Skip to content

Instantly share code, notes, and snippets.

View YSMull's full-sized avatar
🎯
Focusing

ysmull YSMull

🎯
Focusing
View GitHub Profile
@YSMull
YSMull / ap.js
Created December 28, 2018 03:39
Funtion as Applicative in JavaScript
let _ = require('lodash');
let pure = x => _ => x;
let ap = f => g => x => f(x)(g(x));
let add = a => b => a + b;
let multi = a => b => a * b;
let minus3 = a => b => c => a - b - c;
package com.netease.youdata.util;
import java.util.concurrent.ConcurrentHashMap;
public class ExpiredWindow<K, V> {
private Long windowSize;
private ConcurrentHashMap<K, V> dataMap = new ConcurrentHashMap<>();
async function fn1() {
console.log(1);
await new Promise((resolve, reject) => {
console.log(2);
resolve();
})
console.log(3);
};
@YSMull
YSMull / awaitExtractSugar.js
Last active December 28, 2018 09:40
let M = await N 的解糖模式应该是: new Promise((resolve, reject)=>{resolve(N)}).then(M => {...})
let yyy = async function() {
return 123;
}
let multipleAwait = async function () {
let a = await yyy();
let b = await yyy();
console.log(a+b);
}
const co = require('co')
var count = 975;
let test_co = co.wrap(function* (n) {
if (n == count)
return;
yield test_co(n + 1);
});
@YSMull
YSMull / Solution.java
Last active August 17, 2018 03:23
寻找两个数组中是否有公共元素的递归算法
// https://leetcode.com/problems/intersection-of-two-arrays/
class Solution {
public static List<Integer> common = new ArrayList<>();
public static boolean find(int[] arr1, int i1, int j1, int[] arr2, int i2, int j2) {
if (i1 > j1 || i2 > j2) return false;
int mid1 = (i1 + j1) / 2;
int mid2 = (i2 + j2) / 2;
if (arr1[mid1] == arr2[mid2]) {
common.add(arr1[mid1]);
import com.sun.xml.internal.fastinfoset.util.CharArray;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Test3 {
public static List<String> split(String s) {
List<String> res = new ArrayList<>();
@YSMull
YSMull / ExperimentMultiTypeConnMultiTypeConn.java
Created July 4, 2018 09:05
初步完成了一个能连接不同版本mysql的DriverPool
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;
public class Test {
private static void tryConnect(Properties props, String... libs) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
package chkr;
import java.util.function.Function;
@FunctionalInterface
interface CheckedFunction<T> {
T apply(T t) throws Exception;
}
public class Chkr {