Skip to content

Instantly share code, notes, and snippets.

View Pagliacii's full-sized avatar
🎯
Focusing

Jason Huang Pagliacii

🎯
Focusing
View GitHub Profile
@laixintao
laixintao / decent_request.py
Last active February 20, 2024 12:05
Send HTTP requests using python-requests with timeout, tcp reuse(session) and retry.
from requests.adapters import HTTPAdapter, Retry
from requests import Session
retries = Retry(
total=5, backoff_factor=1, status_forcelist=[502, 503, 504]
)
session = Session() # reuse tcp connection
session.mount("http://", HTTPAdapter(max_retries=retries))
session.mount("https://", HTTPAdapter(max_retries=retries))
@cloudwu
cloudwu / sortnumber.c
Created August 1, 2023 05:38
sort telephone number
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#define N (100000063/64)
struct bitset {
uint64_t bits[N];
@vncsna
vncsna / bash_strict_mode.md
Created June 6, 2021 01:59 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@gullyn
gullyn / flappy.html
Last active May 4, 2024 15:35
Flappy bird in 205 bytes (improved!)
<body onload=z=c.getContext`2d`,setInterval(`c.width=W=150,Y<W&&P<Y&Y<P+E|9<p?z.fillText(S++${Y=`,9,9|z.fillRect(p`}*0,Y-=--M${Y+Y},P+E,9,W),P))):p=M=Y=S=6,p=p-6||(P=S%E,W)`,E=49) onclick=M=9><canvas id=c>
package main
import (
"fmt"
"math/rand"
"time"
)
const (
width = 80
#!/bin/bash
###
### my-script — does one thing well
###
### Usage:
### my-script <input> <output>
###
### Options:
### <input> Input file to read.
### <output> Output file to write. Use '-' for stdout.
@Pagliacii
Pagliacii / Makefile
Last active July 28, 2020 04:02
Makefile template, usage: `make all_src_files[ debug=mode]`. From https://tech.davis-hansson.com/p/make/
# use bash as the default shell
SHELL := bash
# ensures each Make recipe is ran as one single shell session, rather than one new shell per line
.ONESHELL:
# use bash strict mode. http://redsymbol.net/articles/unofficial-bash-strict-mode/
.SHELLFLAGS := -eu -o pipefail -c
# remove target files when Make file failed
.DELETE_ON_ERROR:
# warning when referring the undefined variables
MAKEFLAGS += --warn-undefined-variables
@Pagliacii
Pagliacii / swf_header.py
Last active January 26, 2021 11:58
Parsing and getting the header of SWF files. [Adobe SWF File Format Specification](https://www.adobe.com/content/dam/acom/en/devnet/pdf/swf-file-format-spec.pdf)
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
"""
Author: Pagliacii
Copyright © 2020-Pagliacii-MIT License
"""
import math
from struct import unpack
@Pagliacii
Pagliacii / convert.sh
Created April 28, 2020 08:51
Use gnash and ffmpeg to convert *.swf to *.mp4
#!/bin/bash
trap cleanup EXIT
set -eux
set -o pipefail
SWFFILE="$1"
MP4FILE="${SWFFILE%.*}.mp4"
RAWFILE=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).raw
WAVFILE=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).wav
@Pagliacii
Pagliacii / install-ext.sh
Last active April 26, 2019 03:38
This script is used to install the vscode extension manually. Or to install an extension to the code-server.
#!/usr/bin/env bash
#===============================================================================
# This script is used to install the vscode extension manually.
# Or to install an extension to the code-server.
# Inspire by https://github.com/codercom/code-server/issues/171#issuecomment-473690326
#
# It has two way to install the extension:
# 1. by the extension ID
# 2. by the local vsix file