Skip to content

Instantly share code, notes, and snippets.

View ShaneTsui's full-sized avatar
🌏

Shane Tsui ShaneTsui

🌏
View GitHub Profile
@ShaneTsui
ShaneTsui / personal_git_stat.py
Last active October 20, 2023 09:09
Personal git repo contribution statistics based on git log
import os
import re
import math
import subprocess
import matplotlib.pyplot as plt
from collections import defaultdict
import numpy as np
import logging
logging.basicConfig(level=logging.INFO)
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <ctype.h>
#include <strings.h>
#include <string.h>
#include <sys/stat.h>
@ShaneTsui
ShaneTsui / client.cpp
Created July 3, 2020 01:08
Communicate using json string with ZMQ
#include <zmq.hpp>
#include <string>
#include <iostream>
#include "json.hpp"
int main() {
zmq::context_t context;
zmq::socket_t socket(context, ZMQ_REQ);
socket.connect("tcp://localhost:5555");
for (int i = 0; i < 10; ++i) {
@ShaneTsui
ShaneTsui / checkio_solution.py
Last active December 16, 2019 00:51
[Pythonic] #python
# Get the most common letter
text = text.lower()
return max(string.ascii_lowercase, key=text.count)
# Get key from a dictionary with max value
max(a, key=a.get)
@ShaneTsui
ShaneTsui / hyperlink.tex
Created December 9, 2019 02:30
Hyperlink in latex
metadata_ = std::make_shared<rapidjson::Document>(); // false
metadata_ = std::make_shared<rapidjson::Document>(rapidjson::kObjectType); // corret
@ShaneTsui
ShaneTsui / rapidjson2string
Last active November 13, 2019 03:14
translate rapidjson to std::string
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
metadata->Accept(writer);
std::string s = sb.GetString();
@ShaneTsui
ShaneTsui / tex_pseudocode.tex
Last active April 20, 2019 20:06
[tex pseudocode] # latex # pseudocode
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{algorithm}
\caption{Calculate $y = x^n$}
\begin{algorithmic}
\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$
\STATE $y \leftarrow 1$
\IF{$n < 0$}
@ShaneTsui
ShaneTsui / latex_python_code.sty
Created April 19, 2019 07:27
[python code latex] # python # latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pythonhighlight}[2011/09/19 python code highlighting; provided by Olivier Verdier <olivier.verdier@gmail.com>]
\RequirePackage{listings}
\RequirePackage{xcolor}
\renewcommand*{\lstlistlistingname}{Code Listings}
\renewcommand*{\lstlistingname}{Code Listing}
\definecolor{gray}{gray}{0.5}