Skip to content

Instantly share code, notes, and snippets.

View linw1995's full-sized avatar
🎯
Focusing

林玮 (Jade Lin) linw1995

🎯
Focusing
View GitHub Profile
@linw1995
linw1995 / clip_magic.py
Created March 29, 2022 07:24
IPython magic for copying into clipboard in zsh shell on macOS.
from IPython.core.magic import needs_local_scope, register_line_magic
@register_line_magic
@needs_local_scope
def clip(line, local_ns):
import json
import os
import subprocess

Usage

python tailwind_auto_prefix.py <tailwind_template.html
@linw1995
linw1995 / main.go
Created October 14, 2021 13:46
json.Unmarshal can parse null into empty array
package main
import (
"fmt"
"encoding/json"
)
func main() {
var (
lst []string
@linw1995
linw1995 / main.py
Created October 14, 2021 13:44
Use sshfs to mount directory of MacOS into podman machine.
"""
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 September 7, 2021 03:00
Get keyValue history of ETCD in golang.
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 August 27, 2021 02:37
get begin time and end time in Golang.
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println(
@linw1995
linw1995 / csv.go
Created August 20, 2021 09:54
Golang read csv data row into struct
package main
import (
"bytes"
"encoding/csv"
"fmt"
"io"
"reflect"
)
@linw1995
linw1995 / SilceManipulationWithInvoking.go
Last active August 12, 2021 07:06
Golang Troublesome problem
// 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 April 14, 2021 06:57
How to add custom convertors for JSON serializer in Python
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 April 13, 2021 07:16
Get datetime objects in month range in Python.
import calendar
import dataclasses
from datetime import datetime, timezone
@dataclasses.dataclass
class DatetimeRange:
begin: datetime
end: datetime
@classmethod