Skip to content

Instantly share code, notes, and snippets.

@ysmood
ysmood / shuffle_names.go
Last active Dec 18, 2020
Copy the names then run it, it will output to your clipboard, names should be separated by commas
View shuffle_names.go
package main
import (
"math/rand"
"strings"
"github.com/atotto/clipboard"
)
func main() {
View rod-jobcan-demo.go
package main
import (
"os"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/input"
"github.com/go-rod/rod/lib/utils"
)
@ysmood
ysmood / hang.go
Last active Nov 24, 2020
Issue 1151822: CDP call Page.close on the non-exist session id will hang
View hang.go
package main
import (
"context"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/cdp"
"github.com/go-rod/rod/lib/launcher"
)
@ysmood
ysmood / crash_chromedp.go
Last active Oct 30, 2020
Such as when you want to inject a large js helper to the page, chromedp will crash.
View crash_chromedp.go
package main
import (
"context"
"fmt"
"log"
"strings"
"github.com/chromedp/chromedp"
)
View puppeteer-example.js
const puppeteer = require('puppeteer')
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// Total timeout for all operations is not supported, only supports timeout for individual operations.
// Puppeteer doesn't support aborting of slow operation.
page.setDefaultTimeout(5 * 1000)
View storer_bench.go
package main
import (
"fmt"
"time"
"github.com/ysmood/kit"
"github.com/ysmood/storer"
"github.com/ysmood/storer/pkg/kvstore"
)
@ysmood
ysmood / dns-server.go
Created Dec 12, 2019
DNS server example
View dns-server.go
// dns server
package dnser
import (
"net"
"golang.org/x/net/dns/dnsmessage"
)
View tmp.js
let inc = n => ++n
let dec = n => --n
function add (x, y) {
if (y < 0) return add(dec(x), inc(y))
if (y === 0) return x
if (y > 0) return add(inc(x), dec(y))
}
@ysmood
ysmood / .zsh-fzf.sh
Created Jan 9, 2019
fzf config for zsh
View .zsh-fzf.sh
####### fzf ######
if type "fzf" > /dev/null; then
FZF_DEFAULT_OPTS='--layout=reverse --border'
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
selected=( $(fc -rln 1 |
@ysmood
ysmood / nginx.minimal.conf
Last active May 18, 2022
nginx minimal reverse proxy config
View nginx.minimal.conf
events {}
http {
server {
listen 8080;
server_name a.com;
location / {
proxy_pass http://127.0.0.1:8888;
}