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 / changepassword.sh.j2
Last active June 13, 2023 13:24
Create Django super user in ansible
#!/usr/bin/expect
set timeout -1;
spawn {{django_dir}}/venv/bin/python manage.py changepassword {{admin_user}};
expect {
"Password:" { exp_send "{{admin_pass}}\r" ; exp_continue }
"Password (again):" { exp_send "{{admin_pass}}\r" ; exp_continue }
eof
}
@elleryq
elleryq / bingo_table.py
Last active February 8, 2023 10:27
產生 Bingo 表格的程式,裏面的數字是亂數,預設一頁產生 12 個表格,結果會輸出為 PDF。參數是要產生的頁數,輸出檔案會在當前目錄下的 bingo.pdf
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Dependencies:
# * wkhtmltopdf - Convert HTML to PDF
# * pdftk - Merge multiple PDFs to single PDF
# * jinja2 - Template engine
import sys
import os
from itertools import permutations, izip_longest
import random
@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 / insertionsort.cpp
Created March 31, 2015 01:56
Insertion Sort in C++
#include <cstdio>
#include <cstdlib>
void insertionSort(int arr[], int length) {
int i, j, tmp;
for (i = 1; i < length; i++) {
j = i;
while (j > 0 && arr[j - 1] > arr[j]) {
tmp = arr[j];
arr[j] = arr[j - 1];
@elleryq
elleryq / command.py
Created February 5, 2016 07:50
Wrap shell command as python function
# -*- encoding: utf-8 -*-
import subprocess
class command(object):
def __init__(self, cmd):
self._cmd = cmd
def __call__(self, *args, **kwargs):
cmd = [self._cmd]
@elleryq
elleryq / jenkins-cli.sh
Created March 8, 2016 04:04
jenkins-cli.jar wrapper. Download jenkins-cli.jar automatically and wrap it as command.
#!/bin/bash
JENKINS_URL="http://localhost/jenkins"
JENKINS_JAR="/tmp/jenkins-cli.jar"
SSL_CHAR=${JENKINS_URL:4:1}
if [ ! -e $JENKINS_JAR ]; then
WGET="wget $JENKINS_URL/jnlpJars/jenkins-cli.jar -O $JENKINS_JAR"
if [ "$SSL_CHAR" == "s"]; then
@elleryq
elleryq / import_vagrant_box_into_vbox.sh
Last active January 6, 2022 17:18
Import Vagrant box into VirtualBox
#!/bin/bash
BOX=$1
if [ -z $BOX ]; then
echo "Need argments."
exit -1
fi
if [ ! -e $BOX ]; then
@elleryq
elleryq / Main.java
Created December 21, 2014 22:04
Java JDBC with jtds example. 1. Open SQL Configuration Manager to make sure that TCP/IP is enabled and IP/All port is 1433. 2. Open 'Service' to make sure SQL server browser is started. 3. Open SQL Management Studio to make sure user has the permission to access.
// If you cannot connect with SQL server(express), you can check here: http://stackoverflow.com/questions/10522120/connecting-to-local-ms-sql-server
package com.example.jtdsexample;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Main {
public static void main(String[] args) {
@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 {