Skip to content

Instantly share code, notes, and snippets.

View defp's full-sized avatar

lidashuang defp

View GitHub Profile
@defp
defp / merge_list.ex
Created September 1, 2021 03:03
elixir: merge two sorted list
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 June 9, 2021 02:33
puppeteer demo
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});
@defp
defp / socket_server.ex
Created January 6, 2021 02:33
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])
package main
import (
......
"golang.org/x/sync/errgroup"
)
// 一个多阶段的pipeline.使用有限的goroutine计算每个文件的md5值.
func main() {
@defp
defp / SzudzikPairing.go
Last active December 17, 2020 05:02
SzudzikPairing
// 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 November 10, 2020 16:56
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 August 17, 2020 15:32
emacs 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 June 24, 2020 17:31
zerotier 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 14:31
实现一个 Trie (前缀树)
// 实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作。
// 示例:
// Trie trie = new Trie();
// trie.insert("apple");
// trie.search("apple"); // 返回 true
// trie.search("app"); // 返回 false
// trie.startsWith("app"); // 返回 true
package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
memConsumed := func() uint64 {