Skip to content

Instantly share code, notes, and snippets.

Avatar

Eugene Kovalev Abraxos

  • University of Connecticut
View GitHub Profile
View keybase.md

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 Aug 25, 2017
Printing RGB-colored text in xterm/gnome-terminal using Python
View color_string.py
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 Jul 12, 2016
Just a reference about the basics of MessagePack in Python
View msgpack-examples.py
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 Jul 5, 2016
QuickSort implementation in Rust
View quick_sort.rs
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 Jul 5, 2016
Mergesort implementation in Rust
View merge_sort.rs
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 Jul 5, 2016
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.
View heap_sort.rs
struct MinHeap {
store: Vec<i32>,
}
impl MinHeap {
pub fn new() -> Self {
MinHeap { store: vec![] }
}
fn right_idx(&self, parent: usize) -> Option<usize> {