Skip to content

Instantly share code, notes, and snippets.

Avatar
🤯
Mind blowing

林玮 (Jade Lin) linw1995

🤯
Mind blowing
View GitHub Profile
@linw1995
linw1995 / main.go
Created Oct 14, 2021
json.Unmarshal can parse null into empty array
View main.go
package main
import (
"fmt"
"encoding/json"
)
func main() {
var (
lst []string
@linw1995
linw1995 / main.py
Created Oct 14, 2021
Use sshfs to mount directory of MacOS into podman machine.
View main.py
"""
https://github.com/containers/podman/issues/8016#issuecomment-920015800
"""
import getpass
import os
import re
import shlex
import subprocess
from pathlib import Path
@linw1995
linw1995 / go.mod
Last active Sep 7, 2021
Get keyValue history of ETCD in golang.
View go.mod
module github.com/linw1995/etcd_learning
go 1.16
replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.6
google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
require (
@linw1995
linw1995 / day.go
Created Aug 27, 2021
get begin time and end time in Golang.
View day.go
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println(
@linw1995
linw1995 / csv.go
Created Aug 20, 2021
Golang read csv data row into struct
View csv.go
package main
import (
"bytes"
"encoding/csv"
"fmt"
"io"
"reflect"
)
@linw1995
linw1995 / SilceManipulationWithInvoking.go
Last active Aug 12, 2021
Golang Troublesome problem
View SilceManipulationWithInvoking.go
// https://play.golang.org/p/bxTn8L2gf3d
package main
import (
"fmt"
)
func Remove(arr []int, idx int) (rv []int) {
rv = arr[:idx]
rv = append(rv, arr[idx+1:]...)
@linw1995
linw1995 / main.py
Created Apr 14, 2021
How to add custom convertors for JSON serializer in Python
View main.py
import dataclasses
import json
from datetime import datetime
def convertor(v):
if isinstance(v, datetime):
return v.timestamp()
elif dataclasses.is_dataclass(v):
return dataclasses.asdict(v)
@linw1995
linw1995 / demo.py
Created Apr 13, 2021
Get datetime objects in month range in Python.
View demo.py
import calendar
import dataclasses
from datetime import datetime, timezone
@dataclasses.dataclass
class DatetimeRange:
begin: datetime
end: datetime
@classmethod
@linw1995
linw1995 / main.py
Created Apr 9, 2021
Click with async command
View main.py
# Standard Library
import asyncio
import functools
# Third Party Library
import click
def async_command(coro_func):
@functools.wraps(coro_func)
@linw1995
linw1995 / main.py
Last active Apr 8, 2021
A simple example shows how to hook response with mitmproxy in script.
View main.py
# Standard Library
import asyncio
import contextlib
from pathlib import Path
from typing import Callable, Optional
# Third Party Library
import httpx