Skip to content

Instantly share code, notes, and snippets.

View chapter09's full-sized avatar
🚀
Focus

Hao Wang chapter09

🚀
Focus
View GitHub Profile
@chapter09
chapter09 / onetab-delete-all.js
Created April 20, 2024 21:32 — forked from uddhabh/onetab-delete-all.js
OneTab delete all saved tabs script
// https://intuitive-theory.com/notes/onetab-delete-all-saved-tabs-script/
function delete_single() {
for (clickable of clickables) {
if (!clickable || clickable.innerHTML !== "Delete all")
continue;
clickable.click();
return true;
}
return false;
}
import re
from nltk.tokenize.treebank import TreebankWordTokenizer
def preprocess_tweet(tweet):
# # all caps
# allcaps_regex = re.compile(r"([^a-z0-9()<>'`\-]){2,}")
# tweet = re.sub(allcaps_regex, '\1' + ' <allcaps> ', tweet)
# lowercase
tweet = tweet.lower()
@chapter09
chapter09 / tpc.py
Created June 6, 2017 14:14
Parsing tpc address & affiliation
#!/usr/local/bin/python3
import codecs
import re
name_addr = {}
with codecs.open('./tpc', encoding='utf-8') as infd:
for line in infd.readlines():
if "(" not in line:
continue
name = line.split("(")[0][1:].strip()
// Sample Configuration File for Shairport Sync
// Commented out settings are generally the defaults, except where noted.
// General Settings
general =
{
name = "AirPi"; // This means "Hostname" -- see below. This is the name the service will advertise to iTunes.
// The default is "Hostname" -- i.e. the machine's hostname with the first letter capitalised (ASCII only.)
// You can use the following substitutions:
// %h for the hostname,
@chapter09
chapter09 / 0_reuse_code.js
Created July 8, 2016 21:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@chapter09
chapter09 / daemon.md
Created July 8, 2016 21:41 — forked from andreif/daemon.md
A simple unix/linux daemon in Python

A simple unix/linux daemon in Python

Source: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

Access: http://web.archive.org/web/20131025230048/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

by Sander Marechal

I've written a simple Python class for creating daemons on unix/linux systems. It was pieced together for various other examples, mostly corrections to various Python Cookbook articles and a couple of examples posted to the Python mailing lists. It has support for a pidfile to keep track of the process. I hope it's useful to someone.

@chapter09
chapter09 / rsync.py
Created May 8, 2016 20:33
A python script for running rsync in parallel
#!/usr/bin/python
import os
import sys
import subprocess
import argparse
import re
import socket
# argv[1] host lists
# argv[2] source file/directory
class Solution(object):
def containsNearbyAlmostDuplicate(self, nums, k, t):
"""
:type nums: List[int]
:type k: int
:type t: int
:rtype: bool
"""
if not nums:
return False
#!/usr/bin/python
# Author: wh.sjtu@gmail.com
import os, sys
import subprocess
#
# Copy this script to the directory containing submission packages
# excute python ext_convt.py .
#
@chapter09
chapter09 / parse-pcap-rtt.py
Last active December 7, 2017 10:25
A script for iterate pcap files in directories and calculate average RTT
#!/usr/bin/python
import os, sys
import subprocess
# argv[1] analysis directory
if len(sys.argv) == 1:
print """
- argv[1] analysis directory