Skip to content

Instantly share code, notes, and snippets.

Avatar
🦚
I may be slow to respond.

Dashuang Li defp

🦚
I may be slow to respond.
View GitHub Profile
@defp
defp / merge_list.ex
Created Sep 1, 2021
elixir: merge two sorted list
View merge_list.ex
defmodule MergeSoredList do
def merge(l1, []), do: l1
def merge([], l2), do: l2
def merge(l1, l2), do: merge(l1, l2, [])
def merge([], l2, acc), do: acc ++ l2
def merge(l1, [], acc), do: acc ++ l1
def merge([head1| tail1], [head2 | _] = l2, acc) when head1 <= head2 do
merge(tail1, l2, acc ++ [head1])
@defp
defp / puppeteer.js
Created Jun 9, 2021
puppeteer demo
View puppeteer.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: false}); // default is true
const page = await browser.newPage();
// 116.451673,39.923054
await page.setGeolocation({latitude: 39.923054, longitude: 130.451673});
// iphone x
await page.setViewport({ width: 375, height: 812});
View socket_server.ex
defmodule SocketServer do
require Logger
import Sentry.Event
@doc """
Starts accepting connections on the given `port`.
"""
def accept(port) do
{:ok, socket} = :gen_tcp.listen(port,
[:binary, packet: :line, active: false, reuseaddr: true])
View errgroup.go
package main
import (
......
"golang.org/x/sync/errgroup"
)
// 一个多阶段的pipeline.使用有限的goroutine计算每个文件的md5值.
func main() {
@defp
defp / SzudzikPairing.go
Last active Dec 17, 2020
SzudzikPairing
View SzudzikPairing.go
// run https://play.golang.org/p/gVl4Ru_isVA
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(pair(168, 701))
@defp
defp / virtual-service-all-v1.yaml
Created Nov 10, 2020
virtual-service-all-v1.yaml
View virtual-service-all-v1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: productpage
spec:
hosts:
- productpage
http:
- route:
- destination:
@defp
defp / init.el
Created Aug 17, 2020
emacs init.el
View init.el
(setenv "PATH" (concat (getenv "PATH") ":~/go/bin"))
;; Set up package.el to work with MELPA
(require 'package)
(setq package-archives '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(package-initialize)
(package-refresh-contents)
@defp
defp / deployment.yaml
Created Jun 24, 2020
zerotier deployment.yaml
View deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
hello: world
labels:
io.service: zerotier
name: zerotier
spec:
replicas: 1
@defp
defp / Trie.go
Created May 29, 2020
实现一个 Trie (前缀树)
View Trie.go
// 实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作。
// 示例:
// Trie trie = new Trie();
// trie.insert("apple");
// trie.search("apple"); // 返回 true
// trie.search("app"); // 返回 false
// trie.startsWith("app"); // 返回 true
View goroutine_mem.go
package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
memConsumed := func() uint64 {