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
import os | |
import configparser | |
class Config: | |
""" Get config from config file or environment variables. | |
The priority order of config is: Config file > Environment > default_value. | |
The env var is composed by: [SECTION]_[OPTION] | |
For example: | |
get_or_else('smtp', 'BIND_ADDRESS', '127.0.0.1') |
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
from django.db import models | |
from django.contrib.contenttypes.models import ContentType | |
from django.contrib.contenttypes import generic | |
class Poll(models.Model): | |
question = models.CharField(max_length=500) | |
answers = # ... | |
# ... | |
limit = models.Q(app_label='your_app', model='page') | \ |
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 <unpluggedcoder@outlook.com>"] | |
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 | |
################## | |
# 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
#!/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
#![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) { |
NewerOlder