Skip to content

Instantly share code, notes, and snippets.

View Abraxos's full-sized avatar

Eugene Kovalev Abraxos

  • University of Connecticut
View GitHub Profile

Keybase proof

I hereby claim:

  • I am abraxos on github.
  • I am redarmy (https://keybase.io/redarmy) on keybase.
  • I have a public key ASDIcRvF062eba0Et4pKWEIgUExANTnBNZJdjxfEZKTVSwo

To claim this, I am signing this object:

@Abraxos
Abraxos / color_string.py
Created August 25, 2017 15:08
Printing RGB-colored text in xterm/gnome-terminal using Python
def color_string(str, foreground=None, background=None):
reset = '\033[0m'
if foreground:
assert len(foreground) == 3, "Foreground color needs to be a collection of 3 integer values"
R, G, B = int(foreground[0]), int(foreground[1]), int(foreground[2])
foreground = '\033[38;2;{R};{G};{B}m'.format(R=R, G=G, B=B)
else:
foreground = ''
if background:
assert len(background) == 3, "Background color needs to be a collection of 3 integer values"
@Abraxos
Abraxos / msgpack-examples.py
Last active July 12, 2016 02:53
Just a reference about the basics of MessagePack in Python
from msgpack import packb
from msgpack import unpackb
from time import time
def pack(msg):
return packb(msg, use_bin_type=True)
def unpack(msg):
return unpackb(msg, use_list=False, encoding='utf-8')
@Abraxos
Abraxos / quick_sort.rs
Created July 5, 2016 05:33
QuickSort implementation in Rust
fn quicksort(array: &mut Vec<i32>) {
let mut stack = vec![];
stack.push((0, array.len()));
while let Some(top) = stack.pop() {
let (start, end) = top;
match partition(array, start, end) {
None => continue,
Some(pivot_idx) => {
if pivot_idx > start {
// println!("{:?}", (start, pivot_idx));
@Abraxos
Abraxos / merge_sort.rs
Created July 5, 2016 05:31
Mergesort implementation in Rust
fn merge_sort(to_sort: &Vec<i32>) -> Vec<i32>{
if to_sort.len() == 0 {
vec![]
} else if to_sort.len() == 1 {
vector_slice(to_sort,0,1)
} else {
let mid = to_sort.len() / 2;
let first = &vector_slice(to_sort, 0, mid);
let second = &vector_slice(to_sort, mid, to_sort.len());
let first = &merge_sort(first);
@Abraxos
Abraxos / heap_sort.rs
Created July 5, 2016 05:27
Heap Sort in Rust: Includes a min-heap implementation as well as the heap-sort algorithm in Rust. Does not use generics because I haven't learned those yet.
struct MinHeap {
store: Vec<i32>,
}
impl MinHeap {
pub fn new() -> Self {
MinHeap { store: vec![] }
}
fn right_idx(&self, parent: usize) -> Option<usize> {