Skip to content

Instantly share code, notes, and snippets.

View ericls's full-sized avatar

Shen Li ericls

View GitHub Profile
@ericls
ericls / ThenableFuture.py
Created December 25, 2022 18:13
Python thenable future
from asyncio import Future as AsyncioFuture
from concurrent.futures import Future as ConcurrentFuture
from typing import TypeAlias
Future: TypeAlias = AsyncioFuture | ConcurrentFuture
def chain_future(first_future: Future, second_future: Future, transform_result=None):
if first_future.done():
exception = first_future.exception()
@ericls
ericls / 2017-day2.py
Last active December 2, 2017 06:08
2017-day2
sum([max(*row) - min(*row) for row in [[int(i) for i in row.split('\t')] for row in data.split('\n')]])
sum(sum(x/y for y in sorted(row) for x in row if x > y and not x % y) for row in [[int(i) for i in row.split('\t')] for row in data.split('\n')])
@ericls
ericls / async-await-fetch-map.js
Created July 19, 2017 04:03
async/await with fetch and map
// Use hacker news API as example
async function getData() {
const ids = await (await fetch('https://hacker-news.firebaseio.com/v0/topstories.json')).json()
const data = Promise.all(
ids.map(async (i) => await (await fetch(`https://hacker-news.firebaseio.com/v0/item/${i}.json?print=pretty`)).json())
)
return data
}
getData()
@ericls
ericls / dabblet.css
Created April 13, 2016 18:46
Untitled
div.container {
width: 100%;
height: 100%;
background-color: white;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
@ericls
ericls / dabblet.css
Last active April 13, 2016 18:24
Untitled
div.container {
width: 100%;
height: 100%;
background-color: white;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
@ericls
ericls / exercise-maps.go
Created September 24, 2015 18:12
A Tour of Go: Exercise: Maps
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _,k := range strings.Fields(s) {
@ericls
ericls / youtube-demo
Created May 1, 2015 07:45
replace youtube url with embeded video
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" />
<script data-require="jquery" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="script.js"></script>
</head>