Skip to content

Instantly share code, notes, and snippets.

View larryhou's full-sized avatar

larryhou larryhou

  • Tencent
  • Shenzhen, China
View GitHub Profile
@larryhou
larryhou / kill_tcp_connection.md
Created September 26, 2023 07:40
Kill tcp connection without killing parent process
lsof -i tcp:[PORT]
lldb -p [PROCESS_ID]
$ call (int)close([FILE_ID])

@larryhou
larryhou / repeated_enum_typename.md
Last active June 11, 2023 06:20
Fix protobuf-gen-go repeated enum typename in each case

https://github.com/protocolbuffers/protobuf-go

diff --git a/compiler/protogen/protogen.go b/compiler/protogen/protogen.go
index 431e880..5e6b263 100644
--- a/compiler/protogen/protogen.go
+++ b/compiler/protogen/protogen.go
@@ -550,11 +550,14 @@ func newEnumValue(gen *Plugin, f *File, message *Message, enum *Enum, desc proto
 	// An enum value contained in a message is: MessageName_ValueName
 	//
 // For historical reasons, enum value names are not camel-cased.
//
// main.c
// pthread_cond_wait
//
// Created by larryhou on 2023/4/12.
//
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
@larryhou
larryhou / buffer.go
Last active March 24, 2023 09:36
Seekable memory buffer in golang
package io
import (
"bytes"
"fmt"
"io"
)
type Buffer struct {
b bytes.Buffer
@larryhou
larryhou / fitcube.py
Created September 28, 2022 10:17
Concat cubemap slices into one big image with 4:3 aspect ratio
#!/usr/bin/env python
from email.mime import image
import os
import sys
from PIL import Image
def main():
canvas = None # type: Image
data = [(2,1),(0,1),(1,0),(1,2),(1,1),(3,1)]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define HALF_EXPONENT 5
#define HALF_FRACTION (16-HALF_EXPONENT-1)
#define SINGLE_EXPONENT 8
#define SINGLE_FRACTION (32-SINGLE_EXPONENT-1)
@larryhou
larryhou / genastc.py
Created July 6, 2022 02:46
ASTC texture generating
#!/usr/bin/env python
import argparse
import math
import os
import re
import sys
from PIL import Image
@larryhou
larryhou / Hermite.py
Created June 1, 2022 03:42
Hermite interpolation demo
#!/usr/bin/env python3
from argparse import ArgumentParser
from cmath import sin
from random import random
import sys, math
def main():
arguments = ArgumentParser()
arguments.add_argument('--width', '-w', default=1024, type=int, help='svg canvas width')