Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View johnroyer's full-sized avatar

Zero Huang johnroyer

View GitHub Profile
@johnroyer
johnroyer / package.log
Last active March 27, 2024 05:45
ubuntu packages
apt-transport-https ca-certificates gnupg curl nano
vim-nox exuberant-ctags
net-tools fail2ban
aptitude
# Ubuntu Pro
sudo pro attach TOKEN
Feb 4 17:50:51 Zero-Lab-Router-F062F20-C WAN Connection: Fail to connect with some issues.
Feb 4 17:51:01 Zero-Lab-Router-F062F20-C WAN Connection: WAN was restored.
Feb 4 17:51:27 Zero-Lab-Router-F062F20-C WAN Connection: Fail to connect with some issues.
Feb 4 17:51:27 Zero-Lab-Router-F062F20-C WAN Connection: WAN was restored.
Feb 4 17:52:13 Zero-Lab-Router-F062F20-C WAN Connection: Fail to connect with some issues.
Feb 4 17:52:30 Zero-Lab-Router-F062F20-C WAN Connection: WAN was restored.
Feb 4 17:53:50 Zero-Lab-Router-F062F20-C WAN Connection: Fail to connect with some issues.
Feb 4 17:53:51 Zero-Lab-Router-F062F20-C WAN Connection: WAN was restored.
Feb 4 17:54:55 Zero-Lab-Router-F062F20-C WAN Connection: Fail to connect with some issues.
Feb 4 17:54:55 Zero-Lab-Router-F062F20-C WAN Connection: WAN was restored.
@johnroyer
johnroyer / index.html
Created January 16, 2024 08:05
JavaScritp for() break after node removed
<html>
<body>
<ul id="target">
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
<li>5555</li>
</ul>
@johnroyer
johnroyer / deploy.yaml
Last active December 8, 2023 05:06
k8s deployment 格式
- name: phpfpm
image: php:8.1-alpine
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9000
lifecycle:
postStart:
exec:
command:
- "/bin/sh"
@johnroyer
johnroyer / dl.sh
Created November 24, 2023 07:52
script for download youtube video via yt-dlp
#!/usr/bin/env bash
# Usage:
# dl.sh "https://www.youtube.com/watch?v=ec-IgIkEkmA"
#
# 限制檔案名稱長度,主要是為了避開 FAT、NTFS 的限制
/path/to/yt-dlp/yt-dlp.sh \
-o '%(title).150s-%(id)s.%(ext)s' \
-f "bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" \
@johnroyer
johnroyer / query.php
Last active September 22, 2023 06:24
whois query using TCP socket in PHP
<?php
error_reporting(E_ALL);
echo "connection to whois.twnic.net.tw\n";
$address = gethostbyname('whois.iana.org.');
$fp = @fsockopen($address, 43, $errno, $errstr, 5) or die("Socket Error " . $errno . " - " . $errstr);
stream_set_blocking($fp, true);
@johnroyer
johnroyer / composer.json
Created June 6, 2023 03:20
OpenAI GPT-3 PHP example
{
"require": {
"openai-php/client": "^0.5.2",
"symfony/http-client": "^6.2",
"nyholm/psr7": "^1.8",
"guzzlehttp/guzzle": "^7.7"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
@johnroyer
johnroyer / mediawiki-mobile-redirect.js
Last active July 4, 2022 11:26
Redirect Mediawiki mobile page to general page
// ==UserScript==
// @name Redirect Mobile Mediawiki to Desktop URL
// @namespace http://blog.zeroplex.tw/
// @version 0.1
// @description If Mediawiki opened in mobile page, redirect it to general page
// @author zeroplex
// @match https://*.m.wikipedia.org/*
// @grant none
// ==/UserScript==
@johnroyer
johnroyer / linodecreate
Last active March 13, 2022 13:50
Automatically create multiple node via linode-cli
#!/usr/bin/env bash
# usage:
# linodecreate NUM
#
# NUM is the number of node you want to create
genpassword() {
PASS=$( tr -dc A-Za-z0-9 </dev/urandom | head -c 5 | tr '[:upper:]' '[:lower:]' )
echo -n "prefix-$PASS"
@johnroyer
johnroyer / CustomHeaderRequestTrait.php
Created February 23, 2022 06:59
Customize HTTP header in Lumen unit test
<?php
use Illuminate\Testing\TestResponse;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
trait ApiTokenRequestTrait
{
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null, $headers = [])
{
$symfonyRequest = SymfonyRequest::create(