Skip to content

Instantly share code, notes, and snippets.

View cshuaimin's full-sized avatar

Chen Shuaimin cshuaimin

View GitHub Profile
#!/usr/bin/nu
let dev = '/sys/class/backlight/acpi_video0/brightness'
let back = '/tmp/backlight'
gdbus monitor -y -d org.freedesktop.login1
| each { |line|
^echo ($line | parse -r ''LockedHint': <(?P<locked>\w+)>' | get 0.locked)
| into bool
| if $in {
@cshuaimin
cshuaimin / scd.py
Created October 26, 2020 06:23
iTerm2 autolaunch script for scd
#!/usr/local/bin/python3
import iterm2
# This script was created with the "basic" environment which does not support adding dependencies
# with pip.
async def main(connection):
# Your code goes here. Here's a bit of example code that adds a tab to the current window:
app = await iterm2.async_get_app(connection)
tab = app.current_terminal_window.current_tab
@cshuaimin
cshuaimin / sf.go
Created August 10, 2019 03:50
Transfer files over HTTP in the LAN
package main
import (
"fmt"
"net"
"net/http"
"os"
)
func main() {
@cshuaimin
cshuaimin / instagram.py
Last active May 17, 2019 06:07
Instagram downloader
import aiohttp
import asyncio
import os
import re
from pathlib import Path
ROOT_URL = 'https://www.instagram.com/'
PROXY = 'http://127.0.0.1:1080'
HEADERS = {
'User-Agent':
@cshuaimin
cshuaimin / school-timetable.py
Created September 4, 2018 06:21
Generate school timetable in terminal.
import random
from collections import defaultdict
from itertools import cycle
from termcolor import colored
from terminaltables import SingleTable
colors = ['green', 'yellow', 'magenta', 'cyan', 'white']
random.shuffle(colors)
colors = cycle(colors)
from threading import Thread
from queue import Queue
from time import sleep
queue = Queue(maxsize=4)
EXIT_FLAG = object()
def producer():
@cshuaimin
cshuaimin / ssh-port-forward.md
Last active September 6, 2017 15:45
SSH local port forwarding.
i@my-laptop$   ssh -fNTgL      port:    host:hostport    user@server
        |                        |           |                  |
        |                        |           -------------------|------------
        |                        |                              |           |
     ---|------------------------|-------------------------------           |
     |  |                        |                                          |
     |  ----------------         -------------                        --------------
     |                 |                     |                        |            |
 v v v v v