Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀
Rustaceans

Wasin Thonkaew haxpor

🦀
Rustaceans
View GitHub Profile
@haxpor
haxpor / blender_cube_creation.py
Created Jan 15, 2017
Blender Python script to create a new cube, rename it along with set its to new location
View blender_cube_creation.py
import bpy
def strVector3( v3 ):
return str(v3.x) + "," + str(v3.y) + "," + str(v3.z)
# create a new cube
bpy.ops.mesh.primitive_cube_add()
# newly created cube will be automatically selected
cube = bpy.context.selected_objects[0]
@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 / 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 / zhbuild
Last active Apr 27, 2022
A handy shell (bash) script to manage (build, export build setting, and deploy) Zombie Hero project
View zhbuild
#!/bin/bash
## A simple shell script to build Zombie Hero Project from command line
## It involves using the following programs
##
## 1. xcodebuild
## 2. ios-deploy
##
## Commands support (*specific for this script and project)
##
@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 / SimpleDownloaders_future.cpp
Last active Apr 5, 2022
C++ studying of parallel + multithreading (c++11) following https://www.youtube.com/watch?v=_z-RS0rXg9s with some differences. Compile with "g++ -std=c++11 SimpleDownloader.cpp -lpthread -lcurl"
View SimpleDownloaders_future.cpp
/** Downloader app following https://www.youtube.com/watch?v=_z-RS0rXg9s but
* use libcurl (C API) with some adjusted API usage.
*
* Compile with
* g++ -std=c++11 -DNO_PROXY SimpleDownloader.cpp -lpthread -lcurl
* */
#include <iostream>
#include <fstream>
#include <string>
@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);
}