Skip to content

Instantly share code, notes, and snippets.

@saisai
saisai / backtracking_template.py
Created July 22, 2021 13:42 — forked from RuolinZheng08/backtracking_template.py
[Algo] Backtracking Template & N-Queens Solution
def is_valid_state(state):
# check if it is a valid solution
return True
def get_candidates(state):
return []
def search(state, solutions):
if is_valid_state(state):
solutions.append(state.copy())
@saisai
saisai / letsencrypt_2020.md
Created July 5, 2020 06:30 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@saisai
saisai / get_combinations.php
Created July 5, 2020 06:28 — forked from cecilemuller/get_combinations.php
PHP: Get all combinations of multiple arrays (preserves keys)
<?php
function get_combinations($arrays) {
$result = array(array());
foreach ($arrays as $property => $property_values) {
$tmp = array();
foreach ($result as $result_item) {
foreach ($property_values as $property_value) {
$tmp[] = array_merge($result_item, array($property => $property_value));
}
@saisai
saisai / proxy_for_terminal.md
Created June 26, 2020 02:42 — forked from fearblackcat/proxy_for_terminal.md
Set proxy for terminal on mac

Shadowsocks Proxy

apt-get install python-pip
pip install shadowsocks

sudo ssserver -p 443 -k password -m aes-256-cfb --user nobody -d start
@saisai
saisai / linux-mailserver.md
Created March 11, 2020 09:53 — forked from aryklein/linux-mailserver.md
Another linux mail server guide

Setting up a Linux system as a mail server with virtual users

Introduction

Setting up an email server is a difficult process involving a number of different programs, each of which needs to be properly configured. The best approach is to install and configure each individual component one by one, ensuring that each one works, and gradually build your mail server.

This guide covers how to set up a mail server on Debian 8. Most of the steps also should work on Ubuntu 14.04 LTS, considering that Ubuntu 14.04 LTS does not use systemd.

@saisai
saisai / supervisord.sh
Created March 11, 2020 07:01 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@saisai
saisai / README.md
Created November 9, 2018 10:03 — forked from joyrexus/README.md
Perl one-liners

Hi:

perl -e 'print "hello world!\n"'

A simple filter:

perl -ne 'print if /REGEX/'

Filter out blank lines (in place):

@saisai
saisai / trie.py
Created March 7, 2018 04:47 — forked from zshihang/trie.py
Trie
__author__ = "Shihang Zhang"
__status__ = "Prototype"
class TrieNode(object):
""" Trie Node Class
@attrs:
children: a dictionary contains all children nodes
count: an integer indicates the number of occurence of current word
'''
Given a string, reverse all vowels.
'''
def solution(str):
if len(str) in (0, 1):
return str
vowels = set(['a', 'e', 'o', 'u', 'i'])
p, q = 0, len(str)-1
@saisai
saisai / multiple_ssh_setting.md
Created February 21, 2018 04:23 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"