Skip to content

Instantly share code, notes, and snippets.

View crazygit's full-sized avatar

Crazygit crazygit

View GitHub Profile
@crazygit
crazygit / install-dnsmasq-china-list-on-macos.sh
Last active February 17, 2020 11:02
Install dnsmasq-china-list on macos
#!/bin/bash
set -e
# install dnsmasq
brew install dnsmasq
WORKDIR="$(mktemp -d)"
SERVERS=(114.114.114.114 114.114.115.115 180.76.76.76)
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8 223.5.5.5 223.6.6.6
# Dirty cache: 119.29.29.29 182.254.116.116
@crazygit
crazygit / download.sh
Created September 14, 2020 02:20
Download Google Drive Files using wget
#!/usr/bin/env bash
# reffer:
# https://medium.com/@acpanjan/download-google-drive-files-using-wget-3c2c025a8b99
file_name="youer_file_name"
file_id="your_file_id"
confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=${file_id}" -O-| sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=${confirm}&id=${field_id}" -O ${file_name} && rm -rf /tmp/cookies.txt
@crazygit
crazygit / RealTimeDatabaseTest.kt
Last active December 18, 2020 07:03
Extend function to do unit test with Firebase realtime database
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.android.gms.tasks.Task
import com.google.common.truth.Truth.assertThat
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.ValueEventListener
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import org.junit.Before
@crazygit
crazygit / LocalRepository.kt
Last active July 25, 2023 22:31
Jetpack DataStore in MVVM
import com.github.crazygit.tikheart.TikHeartApplication
import com.github.crazygit.tikheart.data.dao.UserInfoDao
import com.github.crazygit.tikheart.data.model.UserInfo
import com.github.crazygit.tikheart.utilities.LocalStorage
object LocalRepository {
private val localStorage = LocalStorage(TikHeartApplication.appContext)
private val localUserDao = UserInfoDao(localStorage)
@crazygit
crazygit / README.md
Last active January 3, 2024 05:12
使用容器快速搭建服务端远程桌面连接环境

项目参考

使用容器快速创建远程桌面的GUI连接

技术实现:

  • Guacamole Server
  • xrdp Server

参考文档

@crazygit
crazygit / python_first_or_none.py
Created July 28, 2021 03:04
firstOrNone Implementation in python
def first_or_none(predicate, seq):
return next(filter(predicate, seq), None)
if __name__ == '__main__':
print(first_or_none(lambda x: x % 2 == 0, [2, 4, 6, 8])) # 2
print(first_or_none(lambda x: x % 2 == 0, [1, 3, 5, 7])) # None
@crazygit
crazygit / go-ethereum-read-event.go
Last active April 26, 2022 08:48
read contract event with go ethereum
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"log"
"math/big"
@crazygit
crazygit / go-ethereum-get-transaction.go
Created April 26, 2022 09:29
Get transaction value and data
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"log"
)
@crazygit
crazygit / traefik-bare-secure-mode.yml
Last active May 8, 2022 14:38
Expose Traefik dashboard in secure mode
# bare secure mode: no https, no basic auth
version: '3.8'
services:
reverse_proxy:
image: traefik:v2.6
command:
# - "--log.level=DEBUG"
# Enable Docker in Traefik, so that it reads labels from Docker services
- "--providers.docker"
@crazygit
crazygit / .env.example
Last active May 8, 2022 14:38
Use traefik in docker swarm cluster, Ultimate configuration
[email protected]
DASHBOARD_DOMAIN=traefik.example.com
WHOAMI_SERVICE_DOMAIN=whoami.example.com
# echo "DASHBOARD_USER=$(htpasswd -nb your_name your_password)" >> .env
DASHBOARD_USER=your_name:$apr1$eMFHYd7e$2rl6G/UF80alLYInwv/tz0