Learning Python: Classes

define class class MyClass: x = 5 create object (instance of a class) p1 = MyClass() print(p1.x) init() function - the constructor class Person: def __init__(self, name, age): self.name = name self.age = age # Now lets create a object p1 = Person("Jason", 4) print(p1.name) print(p1.age) Objects also have methods class PersonM: def __init__(self, name, age): self.name = name self.age = age def says_hello(self): return f"{self.name} says hello" p2 = PersonM("Snow", 30) print(p2.

Learning Python: Session 1

Recently I had the opportunity to share some of my learnings with fellow colleagues. I sincerly thank them and I thought it make sense to share some of my learning here. Setting up a project Python 3.7 Virtual Env Python Package Manager Python Basics Hello World Loops Conditions Lists and Tuples Functions Classes

REST APIs with Rocket for RUST

Excerpts of code snippets to write rust based rest service using the rocket framework. Add dependencies #[macro_use] extern crate rocket; extern crate rocket_contrib; extern crate serde_json; extern crate log; Start Server fn main() { rocket::ignite().mount("/", routes![index, send]).launch(); } Get (Hello World Example) #[get("/")] fn index() -> &'static str { "Hello, world!" } Try it out curl http://localhost:15188/ POST with untyped object #[post("/send", format = "application/json", data ="<data>")] fn send(data: String) -> std::io::Result<String> { let data: Value = serde_json::from_str(&data)?

Writing Automated Test in Rust

Sample Structure #[cfg(test)] mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); } } #[test] annotation before the fn line: this attribute indicates this is a test function, so the test runner knows to treat this function as a test. To run tests use cargo test

Clean Code in Python

Traits of clean code Our code is the most detailed representation of the design. Our ulitmate goal is to make the code as robust as possible And, to write it in a way that minimizes defects or makes them utterly evident, should they occur. Maintainability of code, reducting technical debt, working effectivley in agile development, and managing a successful project. Code Structure Principles and Error Handling Code Structure Principles Dividing Code by Responsibilities Some parts of software a meant to be called directly by users and some by other parts of the code.

Manual Upgrade of Emacs for linux

To install spacemacs upgrade emacs to > 24.4 wget http://mirror.sdunix.com/gnu/emacs/emacs-24.5.tar.gz tar zxvfp emacs-24.5.tar.gz cd emacs-24.5/ ./configure sudo yum -y install libXpm-devel libjpeg-turbo-devel openjpeg-devel openjpeg2-devel turbojpeg-devel giflib-devel libtiff-devel gnutls-devel libxml2-devel GConf2-devel dbus-devel wxGTK-devel gtk3-devel ./configure make sudo make install

RabbitMQ

Key Concepts There are three components defined by the AMQ model. Exchanges For routing messages to their proper destination is an [Exchange|Exchange]. An exchange receives messages sent into RabbitMQ and determines where to send them. Exchanges define routing behaviours that are applied to message. There are multiple exchange types, more on this later. Queues A queue is responsbile for storing received messages and may contain configuration information that defines what it is able to do with a message, and these messages are delivereed in a first-in-first-out order.

Rust and RabbitMQ

A very simple example Start Docker Container for RabbitMQ version: "3" services: rabbitmq: image: "rabbitmq:3-management" ports: - "5672:5672" - "15672:15672" volumes: - 'rabbitmq_data:/data' volumes: rabbitmq_data: Cargo.toml dependency Add the amqp dependency to the cargo.toml file [dependencies.amqp] version="0.1.3" Sample Code Import the crate to your application. In this instance, main.rs extern crate amqp; use amqp::Session; Simple Publish Function fn publish_message() -> () { use crate::amqp::Basic; let mut session = Session::open_url("amqp://localhost//").

Python Conditions and if statements Equals: a == b Not Equals: a != b Less than: a < b Greater than: a > b Greater than or equal to: a >= b

Setting up your environment This is for mac users Developer Tools HomeBrewHome - we will be using macos home brew utility a lot. To install homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" iTerm - it is the terminal window we will be using. If you are comfortable with Terminal window, no problem. brew cask install iterm2 Visual Studio Code - brew cask install visual-studio-code Python We will be developing for Python 3.