Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀
Rustaceans

Wasin Thonkaew haxpor

🦀
Rustaceans
View GitHub Profile
@haxpor
haxpor / poisoned.rs
Last active May 1, 2022
attempt to bypass poisoned mutex (not work yet)
View poisoned.rs
macro_rules! serial_test {
(fn $name: ident() $body: block) => {
#[test]
fn $name() {
let guard = LOCK.try_lock();
if let Ok(mutex) = guard {
$body
}
else {
let err = guard.unwrap_err();
@haxpor
haxpor / sysupdown
Created Apr 7, 2022
rc script to execute command(s) when system is up or down. Note the header lines which is required to have.
View sysupdown
#!/bin/bash
### BEGIN INIT INFO
# Provides: <your service name>
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
# Short-Description: execute commands when system is up or down
# Description: execute commands when system is up or down
@haxpor
haxpor / template_systemd.conf
Created Apr 6, 2022
Guideline and note on crafting out a minimal long running process via systemd config file (sweat and tears in the process)
View template_systemd.conf
[Unit]
Description=My systemd service
After=network.target
# allow cap of 4 attempts to start the process
# within 1 second, if not success, then give up
StartLimitIntervalSec=1
StartLimitBurst=4
[Service]
@haxpor
haxpor / wss_sub_rustweb3.rs
Created Mar 25, 2022
Example of using rust-web3 crate to listen to certain event as emitted from target contract.
View wss_sub_rustweb3.rs
use hex_literal::hex;
use web3::{
contract::{Contract, Options},
futures::{future, StreamExt},
types::{FilterBuilder, Address},
};
use std::str::FromStr;
#[tokio::main]
async fn main() -> web3::contract::Result<()> {
@haxpor
haxpor / cargo_run_example.md
Last active Mar 17, 2022
Rust with cargo on how to run example in the rust project.
View cargo_run_example.md

Run with cargo run --example <example-name>.

In Cargo.toml, configure it with the following if each example needs special crate's features.

[[example]]
name = "json"
required-features = ["json", "serde/derive"]
@haxpor
haxpor / liquidation.json
Created Mar 6, 2022
Processed with jq for json data returned from liquidation websocket of bybit - dev purpose
View liquidation.json
{
"topic": "liquidation.BTCUSD",
"data": {
"symbol": "BTCUSD",
"side": "Buy",
"price": "38931.50",
"qty": "50000",
"time": 1646584807379
}
}
@haxpor
haxpor / example.rs
Created Mar 2, 2022
Use .0 .1 and so on to access unnamed field from the specified arguments to one-line struct declaration
View example.rs
#[derive(Debug)]
struct Token(usize, usize);
fn main() {
let token = Token(1, 2);
println!("{} {}", token.0, token.1);
}
@haxpor
haxpor / make_clean.log
Created Nov 6, 2021
Compare the coverage of removal of files between `make clean` and `make distclean`. The latter has more coverage. Tested against my project https://github.com/haxpor/hashmap_c
View make_clean.log
$ make clean
rm -f test/tests
test -z "libhashmap_c.la" || rm -f libhashmap_c.la
rm -f ./so_locations
rm -rf .libs _libs
rm -rf externals/MurmurHash3/src/.libs externals/MurmurHash3/src/_libs
rm -rf src/.libs src/_libs
rm -rf test/.libs test/_libs
rm -f *.o
rm -f externals/MurmurHash3/src/*.o
@haxpor
haxpor / control
Last active Nov 6, 2021
Verbatim copy of content important configurations files for PPA package for libcurl4-openssl-dev. This is for research purpose.
View control
Source: curl
Section: web
Priority: optional
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
XSBC-Original-Maintainer: Alessandro Ghedini <ghedo@debian.org>
Build-Depends: debhelper (>= 12),
autoconf,
automake,
ca-certificates,
dh-exec,
@haxpor
haxpor / successful-sdl2-manpage_ppa.log
Created Nov 4, 2021
Succesful PPA package build for my sdl2-manpage
View successful-sdl2-manpage_ppa.log
Copy verbatim from https://launchpadlibrarian.net/567163425/buildlog_ubuntu-focal-amd64.sdl2-manpage_0.1.6-git-aae7035-1_BUILDING.txt.gz
----
https://launchpad.net/~haxpor/+archive/ubuntu/combined/+build/22371425
RUN: /usr/share/launchpad-buildd/bin/builder-prep
Kernel version: Linux lgw01-amd64-026 4.15.0-161-generic #169-Ubuntu SMP Fri Oct 15 13:41:54 UTC 2021 x86_64
Buildd toolchain package versions: launchpad-buildd_203~505~ubuntu18.04.1 python3-lpbuildd_203~505~ubuntu18.04.1 sbuild_0.75.0-1ubuntu1 bzr-builder_0.7.3+bzr174~ppa13~ubuntu16.04.1 bzr_2.7.0+bzr6622-10 git-build-recipe_0.3.6~git201906051340.ff11471~ubuntu18.04.1 git_1:2.17.1-1ubuntu0.9 dpkg-dev_1.19.0.5ubuntu2.3 python-debian_0.1.32 python3-debian_0.1.32.
Syncing the system clock with the buildd NTP service...
4 Nov 12:34:41 ntpdate[1782]: adjust time server 10.211.37.1 offset -0.000445 sec