Skip to content

Instantly share code, notes, and snippets.

View zborowa's full-sized avatar

Adrian Zborowski zborowa

View GitHub Profile
@zborowa
zborowa / main.rs
Created November 26, 2018 08:24
Rust guessing game
extern crate rand;
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
@zborowa
zborowa / resize_center_array_image.py
Created May 29, 2015 03:28
Python resize and center array image
def resize_image(img):
"""Return a resized image.
:param img:
"""
cropped_image = crop_image(img)
if len(cropped_image) >= len(cropped_image[0]):
percent = (1.0 - (float(len(cropped_image)) / float(len(img)))) * float(len(img))
else:
percent = (1.0 - (float(len(cropped_image[0])) / float(len(img)))) * float(len(img))
@zborowa
zborowa / center_array_image.py
Last active August 29, 2015 14:22
Python center array image
def center_image(img):
"""Return a centered image.
:param img:
"""
col_sum = np.where(np.sum(img, axis=0) > 0)
row_sum = np.where(np.sum(img, axis=1) > 0)
y1, y2 = row_sum[0][0], row_sum[0][-1]
x1, x2 = col_sum[0][0], col_sum[0][-1]
cropped_image = img[y1:y2, x1:x2]