Skip to content

Instantly share code, notes, and snippets.

View chenggangpro's full-sized avatar
👨‍💻
In The Zone

Gang Cheng chenggangpro

👨‍💻
In The Zone
  • Shanghai,China
  • 20:12 (UTC +08:00)
View GitHub Profile
-- a quick LUA access script for nginx to check IP addresses match an
-- `ip_whitelist` set in Redis, and if no match is found send a HTTP
-- 403 response or just a custom json instead.
--
-- allows for a common whitelist to be shared between a bunch of nginx
-- web servers using a remote redis instance. lookups are cached for a
-- configurable period of time.
--
-- white an ip:
-- redis-cli SADD ip_whitelist 10.1.1.1
// io.netty.buffer.ByteBufUtil
import io.netty.buffer.ByteBuf;
/**
* Returns the reader index of needle in haystack, or -1 if needle is not in haystack.
* This method uses the <a href="https://en.wikipedia.org/wiki/Two-way_string-matching_algorithm">Two-Way
* string matching algorithm</a>, which yields O(1) space complexity and excellent performance.
*/
public static int indexOf(ByteBuf needle, ByteBuf haystack) {
if (haystack == null || needle == null) {
return -1;
@chenggangpro
chenggangpro / m3u8-to-mp4.md
Created May 22, 2022 06:24 — forked from tzmartin/m3u8-to-mp4.md
m3u8 stream to mp4 using ffmpeg

1. Copy m3u8 link

Alt text

2. Run command

echo "Enter m3u8 link:";read link;echo "Enter output filename:";read filename;ffmpeg -i "$link" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $filename.mp4