Data Statistics and Analysis With Java and Python

Java and Python are two of the most popular computer languages in use today. Both are very mature and provide the tools and technology ecosystems to support developing solutions to the challenging problems that arise in the world of data science. Each has its idiosyncrasies. It’s important to understand how they compare tackling different problems, whether they shine or lack the required flexibility to handle the assigned tasks.  When one is preferable over the other or when they work in tandem complementing each other.

Python is a dynamically typed language, very straightforward to work with, and is certainly the language of choice to do complex computations if we don't have to worry about intricate program flows. It provides excellent libraries (Pandas, NumPy, Matplotlib, ScyPy, PyTorch, TensorFlow, etc.) to support logical, mathematical, and scientific operations on data structures or arrays.

How to Utilize Python Machine Learning Models

Ever trained a new model and just wanted to use it through an API straight away? Sometimes you don't want to bother writing Flask code or containerizing your model and running it in Docker. If that sounds like you, you definitely want to check out MLServer. It's a Python-based inference server that recently went GA, and what's really neat about it is that it's a highly-performant server designed for production environments. That means that, by serving models locally, you are running in the exact same environment as they will be in when they get to production.

This blog walks you through how to use MLServer by using a couple of image models as examples.

An Introduction to Milvus Python SDK and API

Background

The following illustration depicts the interaction between SDKs and Milvus through gRPC. Imagine that Milvus is a black box. Protocol Buffers are used to define the interfaces of the server and the structure of the information they carry. Therefore, all operations in the black box Milvus are defined by Protocol API.

The interaction between SDKs and Milvus through gRPC

Milvus Protocol API

Milvus Protocol API consists of milvus.proto, common.proto, and schema.proto, which are Protocol Buffers files suffixed with .proto. SDKs must interact with Milvus with these Protocol Buffers files to ensure proper operation.

Hacking and Securing Python Applications

Securing applications is not the easiest thing to do. An application has many components: server-side logic, client-side logic, data storage, data transportation, API, and more. With all these components to secure, building a secure application can seem really daunting.

Thankfully, most real-life vulnerabilities share the same root causes. And by studying these common vulnerability types, why they happen, and how to spot them, you can learn to prevent them and secure your application.

Diagrams as Code: The Complete How-to-Use Guide

We're seeing more and more tools that enable you to create software architecture and other Diagrams as Code. The main benefit of using this concept is that majority of the Diagrams as Code tools can be scripted and integrated into a built pipeline for generating automatic documentation. The other benefit responsible for the growing use of Diagrams as code to create software architecture is that it enables the use of text-based tooling, which most software developers already use. Furthermore, text is easily version-controllable and diff’able.

Table of Contents

  • What is Diagram as Code?
  • How to install Diagrams
  • How to use Diagrams
  • Conclusion

XSS Prevention Cheatsheet

XSS, or Cross-Site Scripting, is one of the most common vulnerabilities found in applications. In bug bounty programs of different organizations, XSS consistently ranks as the most common vulnerability found. Today, let’s learn how these attacks work, how they manifest in code, and how to prevent them in your programming language. Let’s dive right in!

Anatomy of an XSS attack

XSS happens whenever an attacker can execute malicious scripts on a victim’s browser.

How To Use a Python Variable in an External Javascript (Django)

One way to use a Python variable in an external Javascript is to declare the JS variable in the HTML template through the context object, then pass this variable to the external script code :

HTML
 
<script type="text/javascript"> 
  js_var_from_dj = "{{ django_var }}";
</script>
<script src="https://dzone.com{% static "js/js_file.js" %}" type="text/javascript"></script>

js_file.js :

Book Review: Python Distilled

Python Distilled by David M. Beazley is a pragmatic book that presents some of the most important topics about the Python programming language in a concise form, designed to make it easier to find out the most relevant information bits in a context where resources abound and frequently are just too overwhelming.

Book Structure and Contents

The book is organized into 10 chapters. It starts off with the basics, such as variables, data types, operators, expressions, control flow, and looping. Compared to other books I have read recently, it uses a smaller font size, which is quite readable to me, but it may be less comfortable for some readers. On the other hand, it contributes to making it a lighter and less thick book, compared with other programming manuals. The book uses no syntax highlighting, but code samples are short enough that actually this does not become a problem at all.

How Automation Activates Agile

Harsh, yes... but too often true. Certainly, Agile is a great start for business user collaboration to ensure requirements fit, but it depends on Working Software. This is exactly what automation provides: Working Software, Now. Here's how.

Overview

This article illustrates how Automation, coupled with an Agile Process, can dramatically improve time to market, and reduce requirements risk:

10 Must-know Patterns for Writing Clean Code With Python

What Is Clean Code?

This quote from Bjarne Stroustrup, inventor of the C++ programming language clearly explains what clean code means:

“I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy, and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimizations. Clean code does one thing well.”

Real-Time Pulsar and Python Apps on a Pi

Today we will look at the easy way to build Python streaming applications from the edge to the cloud. Let's walk through how to build a Python application on a Raspberry Pi that streams sensor data and more from the edge to any and all data stores while processing data in event time.

My GitHub repository has all of the code, configuration, and scripts needed to build and run this application.

Reshaping PyTorch Tensors

It is a reasonable thing to expect n-dimensional tensor to have a possibility to be reshaped. Reshape means to change the spatial size of a container that holds underlying data. One can create any n-dimensional tensor that wraps a numerical array as long as the product of dimensions stays equal to the number of the array’s elements. 

Python
 
import torch

# underlying data
data = [1,2,3,4,5,6,7,8] # has 8 elements

# two ways to store identical data
tens_A = torch.tensor(data).reshape(shape=(2,4)) # 2-dimensional tensor of shape (2,4)
tens_B = torch.tensor(data).reshape(shape=(2,2,2)) # 3-dimensional tensor of shape (2,2,2)


Python, NoSQL and FastAPI Tutorial: Web Scraping on a Schedule

Web Scraping image

Can there be other use cases for Cassandra beyond messaging and chat? In this tutorial, we show you how to web scrape on a schedule by integrating the Python framework called FastAPI with Astra DB, a serverless, managed Database-as-a-Service built on Cassandra.

Recently, I caught up with the Pythonic YouTuber Justin Mitchell from CodingEntrepreneurs and we discussed how today’s apps are tackling global markets and issues. He pointed out that Discord stores 120 million messages with only four backend engineers—and that was back in 2017.

A Simple Code Generator Using a Cool Python feature

For my most recent project, I wrote a couple of code generators - three variants of a Python/Spark application generator and at least four variants of an Airflow DAG generator. Different variants were needed as the requirements and the complexity of the output evolved over a period of time. Using this experience, I will show how you can get started on your journey of writing a code generator using a cool feature of Python.

For the purpose of this article, I will use a Python program that generates a basic Python/Spark application to get and display 10 rows of the specified table. The application to be generated is as below

Python
 
import os
import sys
import pyspark
from pyspark import SparkContext
from pyspark.sql import SQLContext
from pyspark.sql import SparkSession

spark_session = SparkSession.builder.appName("generator").getOrCreate()
try:
    df = spark_session.sql("select * from user_names")
    df.show(10, False)
except Exception as e:
    print("Got an error {er}".format(er=str(e)))
spark_session.stop()

Version 1

The simplest method for generating this application is to make use of print statements as below