Skip to content

Instantly share code, notes, and snippets.

View c4pt0r's full-sized avatar

dongxu c4pt0r

View GitHub Profile
@c4pt0r
c4pt0r / How
Last active February 25, 2024 14:33
Build your own Dropbox using TiDB Cloud Free Tier + JuiceFS + AWS S3 in 2 lines.
1. Open S3 service in AWS, create bucket and get the access point, like this: https://${bucket-name}.s3.us-west-2.amazonaws.com
2. Go to https://tidbcloud.com and register a new free TiDB instance (10G), get a MySQL endpoint, and make sure the traffic filter is properly configured to allow public access.
3. Install the juicefs client locally in Distributed Mode (https://juicefs.com/docs/community/getting-started/for_distributed)
4. initialize and mount FUSE according to the following two lines:
# juicefs format --storage s3 \
--bucket https://${bucket-name}.s3.us-west-2.amazonaws.com \
--access-key ${aws-access-key} \
--secret-key ${aws-secret} \
mysql://${mysql-user}:${mysql-password}@\(your-cloud-tidb.prod.aws.tidbcloud.com:4000\)/juice \
@c4pt0r
c4pt0r / main.go
Created April 13, 2023 00:26
Small tool to split large CSV file
package main
import (
"bufio"
"bytes"
"compress/gzip"
"encoding/base64"
"encoding/csv"
"flag"
"fmt"
@c4pt0r
c4pt0r / vortex.go
Created March 7, 2023 00:36
Vortex1.go
package main
import (
"fmt"
"math"
"math/rand"
"os"
"os/exec"
"strconv"
"strings"
@c4pt0r
c4pt0r / dlock.go
Created March 19, 2017 11:26
simple distributed lock using TiKV
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"math/rand"
"time"
@c4pt0r
c4pt0r / poll.py
Created September 15, 2022 06:19
poll db for new rows, like tail -f
#!/usr/bin/env python3
# Usage:
# ./poll.py --host <xxx.tidbcloud.com> --port 4000 --user <username> --password <pwd> | jq --unbuffered .text | grep http
import signal
import time
import os
import argparse
import MySQLdb
parser = argparse.ArgumentParser(description='polls db for new rows')

Install TiUP

$ curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

Start a TiDB Cluster

$ tiup playground
@c4pt0r
c4pt0r / bigetc.go
Last active June 7, 2022 01:31
bigetc.go
package bigetc
import (
"database/sql"
"time"
"github.com/c4pt0r/log"
_ "github.com/go-sql-driver/mysql"
)
@c4pt0r
c4pt0r / jq.go
Last active May 9, 2022 01:48
Job Queue using TiDB
package main
import (
"database/sql"
"fmt"
"log"
"math/rand"
"time"
"github.com/fatih/color"
@c4pt0r
c4pt0r / task-aurora.yaml
Created May 16, 2019 03:51
task-aurora.yaml
name: test
task-mode: all
is-sharding: false
meta-schema: "dm_meta"
remove-meta: false
enable-heartbeat: false
ignore-checking-items: ["dump_privilege", "replication_privilege"]
target-database:
host: ""
#!/usr/bin/env python3
import time
import slack
import os
import sqlite3
from requests_html import HTMLSession
client = slack.WebClient(os.environ.get('SLACK_BOT_TOKEN'))
session = HTMLSession()