Skip to content

Instantly share code, notes, and snippets.

View yanxurui's full-sized avatar

Xurui Yan yanxurui

View GitHub Profile
@yanxurui
yanxurui / GreeterService.cs
Created December 1, 2023 13:56
GrpcGreeter server code that compares kestrel vs http.sys and TCP/IP vs unix domain socket vs named pipe
using Google.Protobuf;
using Grpc.Core;
using GrpcGreeter;
namespace GrpcGreeter.Services;
public class GreeterService : Greeter.GreeterBase
{
private static Dictionary<uint, ByteString> responseMap;
@yanxurui
yanxurui / Program.cs
Last active November 27, 2023 08:31
A wrk like http benchmarking tool written in C# .NET 8 that supports http/3
// This is a wrk like http benchmarking tool written in C# that supports http/3
using CommandLine;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
var latencies = new ConcurrentBag<double>();
var failedRequest = new ConcurrentBag<HttpStatusCode>();
@yanxurui
yanxurui / run_module_dec.py
Created October 16, 2018 22:17
a decorator to run a module and capture stdin/stdout
def run(module_path):
# run a module
# capture standard input and output
def wrapper(input):
stream_in = StringIO(input)
stream_out = StringIO()
stdin_ = sys.stdin
stdout_ = sys.stdout
sys.stdin = stream_in
sys.stdout = stream_out
@yanxurui
yanxurui / convert.sh
Created April 19, 2018 06:21
convert vdat to mp4
set -x
src="/Users/yxr/Downloads/in/"
for fullfile in "$src"*.vdat
do
filename="${fullfile##*/}"
output="/Users/yxr/Downloads/out/${filename%.*}.mp4"
echo $output
ffmpeg -i "$fullfile" -codec copy "$output"
done
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>
void error(char *msg) {
//Example code: A simple server side code, which echos back the received message.
//Handle multiple socket connections with select and fd_set on Linux
#include <stdio.h>
#include <string.h> //strlen
#include <stdlib.h>
#include <errno.h>
#include <unistd.h> //close
#include <arpa/inet.h> //close
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <errno.h>
@yanxurui
yanxurui / libev_model.c
Created June 4, 2017 04:55
libev steps for beginners
/*all watcher callbacks have a similar signature
callback arguments:
1. event loop pointer, or use EV_P_ macro
2. the registered watcher structure
3. a bitset of received events
*/
static void my_cb (struct ev_loop *loop, ev_io *w, int revents)
{
// ...
// stop watching for events at any time by calling the corresponding stop function ev_TYPE_stop (loop, watcher *)
@yanxurui
yanxurui / pthread_client.c
Created June 4, 2017 04:53
chat room example based on multithread
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#define BUFFER_SIZE 1024
@yanxurui
yanxurui / libev_client.c
Last active June 4, 2017 04:50
chat room example based on libev
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <ev.h>
#define BUFFER_SIZE 1024