This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pallette in BGR format | |
# Preview & reference: https://www.rapidtables.com/web/color/RGB_Color.html | |
ALICE_BLUE = (255, 248, 240) | |
ANTIQUE_WHITE = (215, 235, 250) | |
AQUA = (255, 255, 0) | |
AQUA_MARINE = (212, 255, 127) | |
AZURE = (255, 255, 240) | |
BEIGE = (220, 245, 245) | |
BISQUE = (196, 228, 255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for object in array | |
# Thanks to https://www.starkandwayne.com/blog/bash-for-loop-over-json-array-using-jq/ | |
example='[{"name":"foo"},{"name":"bar"}]' | |
for row in $(echo "${example}" | jq -rc '.[] | @base64'); do | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
# usage: $(_jq '.xxx') | |
echo $(_jq '.name') | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "jrpc" | |
version = "0.1.0" | |
authors = ["unpluggedcoder <[email protected]>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
log = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/koute/memory-profiler/blob/master/preload/src/spin_lock.rs | |
use std::sync::atomic::{AtomicBool, Ordering}; | |
use std::ops::{Deref, DerefMut}; | |
use std::cell::UnsafeCell; | |
use std::mem::transmute; | |
pub struct SpinLock< T > { | |
pub value: UnsafeCell< T >, | |
pub flag: AtomicBool | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given by Alice: https://users.rust-lang.org/t/cstring-into-string-s-behavior-on-android/44470/3 | |
use std::ffi::CStr; | |
use std::os::raw::c_char; | |
const PR_GET_NAME: libc::c_int = 16; | |
unsafe fn call_prctl(allocation: &mut Vec<u8>) -> &CStr { | |
let ptr = allocation.as_mut_ptr() as *mut c_char; | |
let ret: libc::c_int = libc::prctl(PR_GET_NAME, ptr); | |
if ret != 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Ubuntu 18.04 | |
# Rust + Postgresql 10 + redis development environment | |
# Zsh | |
sudo apt install zsh | |
# oh-my-zsh | |
# using curl | |
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
# or using wget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
################## | |
# For Chinese ONLY | |
tee -a ~/.zshrc <<'EOF' | |
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup | |
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup | |
EOF | |
################## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(slice_patterns)] | |
impl Solution { | |
pub fn is_match(s: String, p: String) -> bool { | |
is_match(s.as_bytes(), p.as_bytes()) | |
} | |
} | |
fn is_match(s: &[u8], p: &[u8]) -> bool { | |
match (p, s) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FullPaths(argparse.Action): | |
"""Expand user- and relative-paths""" | |
def __call__(self, parser, namespace, values, option_string=None): | |
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values))) | |
def is_dir(dirname): | |
"""Checks if a path is an actual directory""" | |
if not os.path.isdir(dirname): | |
msg = "{0} is not a directory".format(dirname) | |
raise argparse.ArgumentTypeError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import shared_task | |
@shared_task | |
def write_task(msg): | |
# Write log in Network IO | |
print(msg) | |
celery_handler = AsyncLogDispatcher(write_task, use_thread=False, use_celery=True) | |
celery_handler.setLevel(logging.INFO) | |
logger.addHandler(celery_handler) |
NewerOlder