Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
yi-jiayu / autoreplier.py
Last active January 27, 2024 11:09
Automatic replies for Telegram (Updated for Telethon 1.6.2)
import time
from telethon import TelegramClient, events
# sample API_ID from https://github.com/telegramdesktop/tdesktop/blob/f98fdeab3fb2ba6f55daf8481595f879729d1b84/Telegram/SourceFiles/config.h#L220
# or use your own
api_id = 17349
api_hash = '344583e45741c457fe1862106095a5eb'
# fill in your own details here
@yi-jiayu
yi-jiayu / count_messages.py
Last active January 21, 2024 15:17
Using Telethon and the Telegram API to count the number of messages in each of your recent conversations
from telethon import TelegramClient
from telethon.errors.rpc_errors_401 import SessionPasswordNeededError
# (1) Use your own values here
api_id = 17349
api_hash = '344583e45741c457fe1862106095a5eb'
phone = 'YOUR_NUMBER_HERE'
username = 'username'
asn() {
if [ -z "$1" ]
then
echo "usage: asn url" 1>&2
return 1
fi
ips=$(dig $DIG_ARGS +short $1)
if [ -z "$ips" ]
then
@yi-jiayu
yi-jiayu / hotcorners.sh
Last active January 27, 2023 15:04
A script to quickly configure Hot Corners from a file on macOS (https://blog.jiayu.co/2018/12/quickly-configuring-hot-corners-on-macos/)
#!/usr/bin/env bash
set -e
config_dir=${HOTCORNERS_CONFIG_DIR:-$HOME/.hotcorners}
if [ -z "$1" ]; then
echo "usage: hotcorners profile" 1>&2
exit 1
fi
import signal
import sys
from google.cloud import language
from google.api_core.exceptions import InvalidArgument
# create a Google Cloud Natural Languague API Python client
client = language.LanguageServiceClient()
@yi-jiayu
yi-jiayu / dashboard.json
Last active April 18, 2022 04:11
greenpath.dev dashboard for https://github.com/actions
{
"name": "Actions dashboard",
"builds": [
{
"owner": "actions",
"repo": "starter-workflows",
"ref": "main",
"include_prs": true
},
{
@yi-jiayu
yi-jiayu / Linear Escape.i7
Created August 3, 2020 15:18
Linear Escape
"Linear Escape" by Jiayu Yi
Dead End is a dark room. "[if unvisited]You wake up in[otherwise]The room you woke up in is[end if] a small room with a single exit to the south."
A lit thing called a torch is in the Dead End.
The strangely-shaped rock is carried by the player.
South of the Dead End is the Overgrown Chamber. The Overgrown Chamber is a dark room. "You find yourself in a large chamber. The walls are covered with vegetation, and [sturdy vines] hang from the ceiling. The middle is occupied by a large, [ceremonial brazier]. [if the ceremonial brazier is lit]There are exits to the north and south.[otherwise]There is an exit to the north, but a stone door blocks the way south."
@yi-jiayu
yi-jiayu / sse_demo_plug.ex
Created February 8, 2020 14:45
Server-sent events in Elixir with Plug
defmodule SSEDemoPlug do
use Plug.Router
plug Plug.Logger
plug(:match)
plug(:dispatch)
get "/" do
html = """
<ul></ul>
@yi-jiayu
yi-jiayu / zebra.pl
Created January 16, 2020 15:59
Prolog solution to the Zebra Puzzle (https://en.wikipedia.org/wiki/Zebra_Puzzle)
:- use_module(library(clpfd)).
zebra(Colors, Nationalities, Pets, Beverages, Cigarettes) :-
Colors = [Red, Green, Ivory, Yellow, Blue],
Nationalities = [English, Spanish, Ukrainian, Norweigian, Japanese],
Pets = [Dog, Snails, Fox, Horse, Zebra],
Beverages = [Coffee, Tea, Milk, Orange, Water],
Cigarettes = [Old, Kools, Chesterfields, Lucky, Parliaments],
Colors ins 1..5,
Nationalities ins 1..5,
@yi-jiayu
yi-jiayu / git-safe-to-delete
Created October 1, 2019 12:49
Script to check if a local Git repository can be deleted safely without losing any work
#!/usr/bin/env bash
# Check if the working tree is clean.
# The working tree is clean if the output of `git status --porcelain` is empty.
[ -z "$(git status --porcelain)" ] || echo "Working tree not clean."
# Check if there are any stashes.
# There are no stashes if the output of `git stash list` is empty.
[ -z "$(git stash list)" ] || echo "Stash list not empty."