Skip to content

Instantly share code, notes, and snippets.

View Pagliacii's full-sized avatar
🎯
Focusing

Jason Huang Pagliacii

🎯
Focusing
View GitHub Profile
@Pagliacii
Pagliacii / README.md
Last active May 19, 2021 10:52
Using Prolog to solve a password puzzle.

Password Puzzle

Here has a three-digit password. It satisfies all constraints below:

  1. 682: One correct digit in the correct position.
  2. 614: One correct digit in the wrong position.
  3. 206: Two correct digits, neither in the correct position.
  4. 738: No correct digits.
  5. 870: One correct digit in the wrong position.
@Pagliacii
Pagliacii / houses_puzzle.pl
Created May 19, 2021 13:05
Who owns the zebra and who drinks water?
/* Houses logical puzzle: who owns the zebra and who drinks water?
*
* 1. Five colored houses in a row, each with an owner, a pet, cigarettes, and a drink.
* 2. The English lives in the red house.
* 3. The Spanish has a dog.
* 4. They drink coffee in the green house.
* 5. The Ukrainian drinks tea.
* 6. The green house is next to the white house.
* 7. The Winston smoker has a serpent.
* 8. In the yellow house they smoke Kool.
@Pagliacii
Pagliacii / floors_puzzle.pl
Created June 1, 2021 08:20
The following puzzle takes from Dinesman's Superior Mathematical Puzzles in 1968.
/* Where does everyone live?
*
* 1. Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment house that contains only five floors.
* 2. Baker does not live on the top floor.
* 3. Cooper does not live on the bottom floor.
* 4. Fletcher does not live on either the top or the bottom floor.
* 5. Miller lives on a higher floor than does Cooper.
* 6. Smith does not live on a floor adjacent to Fletcher's.
* 7. Fletcher does not live on a floor adjacent to Cooper's.
*/
@Pagliacii
Pagliacii / liars-puzzle.pl
Last active June 2, 2021 07:26
Solve the following “Liars” puzzle from The Sphinx Problem Book by Phillips Hubert in 1934.
/* What in fact was the order in which the five girls were placed?
*
* Five schoolgirls sat for an examination. Their parents--so they thought--showed an undue degree of interest
* in the result. They therefore agreed that, in writing home about the examination, each girl should make one
* true statement and one untrue one. The following are the relevant passages from their letters:
*
* 1. Betty: "Kitty was second in the examination. I was only third."
* 2. Ethel: "You'll be glad to hear that I was on top. Joan was 2nd."
* 3. Joan: "I was third, and poor old Ethel was bottom."
* 4. Kitty: I came out second. Mary was only fourth."
@Pagliacii
Pagliacii / father-puzzle.pl
Created June 2, 2021 09:17
Who is Lorna’s father? Use Prolog to solve a logic puzzle.
/* Who is Lorna's father?
*
* Mary Ann Moore’s father has a yacht and so has each of his four friends: Colonel Downing, Mr. Hall, Sir Barnacle Hood, and Dr. Parker.
* 1. Each of the five also has one daughter and each has named his yacht after a daughter of one of the others.
* 2. Sir Barnacle’s yacht is the Gabrielle.
* 3. Mr. Moore owns the Lorna.
* 4. Mr. Hall the Rosalind.
* 5. The Melissa, owned by Colonel Downing, is named after Sir Barnacle’s daughter.
* 6. Gabrielle’s father owns the yacht that is named after Dr. Parker’s daughter.
*/
@Pagliacii
Pagliacii / rust.json
Last active June 26, 2021 09:24
Useful snippets for Rust in VSCode.
{
// Place your snippets for rust here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
#!/usr/bin/env python
import string
import textwrap
import functools
def filter_not_upper(text: str) -> str:
return "".join(filter(lambda c: c in string.ascii_uppercase, text))
@Pagliacii
Pagliacii / proxy.sh
Last active September 22, 2021 11:25
A shell script to run command behind the proxy.
#!/usr/bin/env bash
# 0. (Optional) Rename this script name to "proxy"
# 1. Replace the <protocol>, <ip> and <port> to the actual value of your proxy respectively.
# 2. Run this command `sudo chmod +x <path to proxy>` to make sure this script is executable.
# 3. Add this script path to the PATH environment variable.
# 4. Run your actual command like this: `proxy ping www.google.com`.
PROXY="<protocol>://<ip>:<port>"
export ALL_PROXY=$PROXY
@Pagliacii
Pagliacii / number.py
Last active September 23, 2021 14:58
A Number class
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
import re
def str_to_int(s: str) -> int:
if not s:
return 0
i = ord(s[0]) - ord("0")
@Pagliacii
Pagliacii / query.py
Created October 24, 2021 03:30
Query IP location based on QQWry.dat file
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import mmap
import struct
import socket
import pathlib
from typing import Tuple