Skip to content

Instantly share code, notes, and snippets.

@elleryq
elleryq / shorten_path.py
Created July 1, 2023 14:37
shorten_path
#!/usr/bin/env python3
import argparse
import sys
import pathlib
def cut_path(path, limit):
if len(path)>limit:
parts = list(pathlib.PurePath(path).parts)
# print(parts)
@elleryq
elleryq / README.md
Created October 23, 2022 16:18 — forked from mukeshmodiindia/README.md
Deploy Percona Server for MongoDB Replica set with Ansible

Deploy the MongoDB Replica set using Ansible.

Pre-requisite:

Make sure to add hosts entries in /etc/hosts in all mongod instance. Verify whether it's reachable, i.e within network. Check it with ping or telnet. ping hostname/ip telnet hostname/ip mongo_port Quick guide

Adjust the hosts details in inventory. Adjust the global variables in group_vars/all

@elleryq
elleryq / VirtualKeyboard.swift
Created January 18, 2021 04:00 — forked from ethanhuang13/VirtualKeyboard.swift
MacBook Air M1 Zhuyin Keyboard written with SwiftUI ~=300 LOC, < 4hrs
//
// VirtualKeyboard.swift
// MacBook Air M1 Zhuyin Keyboard
// Written with SwiftUI ~=300 LOC, < 4hrs
// Created by Ethan Huang on 2021/1/13.
// Twitter: @ethanhuang13
import SwiftUI
struct VirtualKeyboard: View {
@elleryq
elleryq / script-template.sh
Created January 9, 2021 02:20 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@elleryq
elleryq / show_confirm_dialog.dart
Last active June 20, 2020 14:45
Show confirm dialog in flutter
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(""),
content: Text("確定刪除?"),
actions: <Widget>[
FlatButton(
child: Text("取消"),
onPressed: () {
@elleryq
elleryq / sysctl_99-custom.conf
Last active March 23, 2020 03:17
Redis configuration and make connections maximize
vm.overcommit_memory=1
net.ipv4.tcp_syncookies=0
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=1200
net.ipv4.route.gc_timeout=100
net.ipv4.ip_local_port_range=1024 65000
net.ipv4.tcp_syn_retries=5
net.ipv4.tcp_synack_retries=5
@elleryq
elleryq / proxy.config.json
Created January 30, 2020 02:11
Angular CLI - proxy.json
{
"/api/*": {
"target": "http://localhost:8000",
"changeOrigin": true,
"secure": false,
"logLevel": "debug"
},
"/ws/*": {
"target": "http://localhost:8000",
"changeOrigin": true,
@elleryq
elleryq / playbook.yml
Created January 30, 2020 01:58
Generate self-signed ssl certification
- name: Simply generating self-signed SSL certs
hosts: all
become: yes
become_method: sudo
tasks:
- name: backup old cert
command: mv /etc/nginx/ssl/nginx.crt /etc/nginx/ssl/nginx.crt.bak
- name: create self-signed SSL cert
command: openssl req -new -nodes -x509 -subj "/C=TW/ST=Taipei/L=Taiwan/O=Biotrump/CN={{ansible_fqdn}}" -days 3650 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -extensions v3_ca creates=/etc/nginx/ssl/nginx.crt
@elleryq
elleryq / Jenkinsfile
Created December 24, 2019 01:47
簽出 django 專案原始碼並且執行測試並打包為 zip
#!/usr/bin/groovy
// vi: ft=groovy
import hudson.model.*
import hudson.EnvVars
import groovy.json.JsonSlurperClassic
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import java.net.URL
@elleryq
elleryq / .vimrc
Created October 15, 2019 15:52
.vimrc for go. First, you need to install pathogen: https://blog.longwin.com.tw/2014/07/vim-use-pathogen-manage-plugin-2014/
" First, you need to install pathogen: https://blog.longwin.com.tw/2014/07/vim-use-pathogen-manage-plugin-2014/
execute pathogen#infect()
set nocompatible
set t_Co=256
set nu " line number
set cursorline
" set cursorcolumn
set showmatch