Skip to content

Instantly share code, notes, and snippets.

View wotchin's full-sized avatar
☺️
Connect to me using X/twitter @wotchin_real

Wotchin wotchin

☺️
Connect to me using X/twitter @wotchin_real
View GitHub Profile
@wotchin
wotchin / psql-srv.py
Last active September 21, 2023 06:36 — forked from eatonphil/psql-srv.py
postgres "server" wire protocol example (ported python3)
# th30z@u1310:[Desktop]$ psql -h localhost -p 55432
# Password:
# psql (9.1.10, server 0.0.0)
# WARNING: psql version 9.1, server version 0.0.
# Some psql features might not work.
# Type "help" for help.
#
# th30z=> select foo;
# a | b
# ---+---

ZDQ3NTMtOTRjZTMKZjIxMmItZDE0YmYKYTI5MWMtYmY5NjAKMWY3OWYtMTc1ZjIKNWQ0NjItNjQxZTIKZjYzZjQtM2E2NjcKZGM2YzUtMjYyNzIKOTBiMjgtNTM3YmEKYTc3ODUtOWI5Y2EKM2U3ZjktMTY5YmUKYzNiNjMtZjlhZTcKNTcyNWQtMTRlNjgKMDhiM2EtZGVlNjQKZjE2ODItM2IxNWQKM2UzMmMtYzllNDgKOTE4MDAtZDk3N2U=

@wotchin
wotchin / self_registering.cpp
Created May 30, 2023 02:27
C++: Self-registering functions using macros for test libraries
// ---- .hpp ----
// Refer to
// https://blog.rubenwardy.com/2019/02/17/cpp-self-registering-test-macros
#include <functional>
#define Test(name) \
void test_##name(); \
static bool test_##name##_registered = TestFactory::Register(#name, &test_##name); \
void test_##name()
@wotchin
wotchin / modify_mem.c
Created March 25, 2023 03:04
A demo to show how to modify another process' memory
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@wotchin
wotchin / ArrayDeque
Created February 10, 2018 06:12
from ArrayDeque.java file, find 2^n value. //寻找最临近的2的指数次数值,结果-1可以作为mask使用
private static int getCapacity(int numElements) {
int initialCapacity = numElements;
initialCapacity |= (initialCapacity >>> 1);
initialCapacity |= (initialCapacity >>> 2);
initialCapacity |= (initialCapacity >>> 4);
initialCapacity |= (initialCapacity >>> 8);
initialCapacity |= (initialCapacity >>> 16);
initialCapacity++;
if (initialCapacity < 0) // Too many elements, must back off
initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
@wotchin
wotchin / gist:5da42fe0ccb29d8abbd5ffbde886d84f
Created January 31, 2018 11:20
Modal-Alert replace alert() function.
function modalRender(text) {
var modal = $("<div class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"alertModal\" aria-hidden=\"true\"></div>").append(
$("<div class=\"modal-dialog\"></div>").append(
$("<div class=\"modal-content\"></div>").append(
$("<div class=\"modal-body\">"+text+"</div>")
)
)
);
modal.modal();
}
[Link](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference)
link url:
>https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference
for ex.
```
- in the line: $\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N$。
- block:
$$ x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$