Skip to content

Instantly share code, notes, and snippets.

View johnroyer's full-sized avatar

Zero Huang johnroyer

View GitHub Profile
@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 / 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(
@johnroyer
johnroyer / PHPStorm-Darcula-customized.icls
Created February 18, 2022 13:43
Jetbrains IDE syntax highlight scheme without italic
<scheme name="Darcula" version="142" parent_scheme="Darcula">
<metaInfo>
<property name="created">2022-02-18T21:35:09</property>
<property name="ide">PhpStorm</property>
<property name="ideVersion">2021.3.2.0.0</property>
<property name="modified">2022-02-18T21:35:29</property>
<property name="originalScheme">_@user_Darcula</property>
</metaInfo>
<attributes>
<option name="DEFAULT_DOC_COMMENT">
@johnroyer
johnroyer / Sitemap.php
Last active February 17, 2022 06:17
Sitemap Middleware for Laravel
<?php
/**
* This file is orginzed from @FDisk from StackOverflow
* @see https://stackoverflow.com/a/28608156/8681141
*/
namespace App\Http\Middleware;
use Closure;
@johnroyer
johnroyer / getIp.php
Created June 8, 2021 05:03
get user IP
<?php
function getServerKey(string $key): string
{
if (array_key_exists($key, $_SERVER)) {
return $_SERVER[$key];
}
return '';
}
$orderedKey = [
@import url(../../../stylesheets/application.css);
/* A1 theme version 2.0.0 by Kirill Bezrukov www.redmineup.com */
#header {
background: #394956;
min-height: 5em;
padding: 0px;
min-height: initial;
@johnroyer
johnroyer / main.js
Last active May 31, 2024 07:58
try to new Pin object on webduino
var webduino = require('webduino-js');
board = new webduino.WebArduino('Ge8pn');
board.on('ready', function (board) {
var pin = new webduino.core.Pin(board, 10, Pin.DOUT);
board.systemReset();
board.samplingInterval = 250;
var replay = new webduino.module.Relay(board, 10);