How To Split Strings in Java

Split Strings in Java

The string split() method in Java splits a given string around matches of the given regular expression. Example Java StringTokenizer, and String Split. The StringTokenizer class allows us to break a string into tokens in an application. This class is a legacy class retained for purposes of consistency although its use is discouraged in new … Read more

Substrings in Java

Substrings in Java

A segment of the string is called substring. To put it another way, substring is a subset of another string. StartIndex is inclusive and endIndex is exclusive when substring. Substrings String s = “this is an example”; String a = s.substring(11); // a will hold the string starting at character 11 until the end (“example”) … Read more

StringBuffer and StringBuilder Classes in Java

StringBuffer and StringBuilder Classes in Java

Introduction to Java StringBuffer class. In Java StringBuffer class. StringBuffer is a peer string class that provides much of the string functionality. String represents fixed-length, immutable sequences of characters while StringBuffer represents growable, writable sequences of characters. StringBuffer class Key Points: used to created mutable (modifiable) string. Mutable: Which can be changed. is thread-safe i.e. … Read more

Python Anti Patterns Tutorial

Python Anti-Patterns are another important thing to understand for programmers to master this programming language. Learn more here. Overzealous except clause Exceptions are powerful, but a single overzealous except clause can take it all away in a single line. try: res = get_result() res = res[0] log(‘got result: %r’ % res) except: if not res: … Read more

Secure Shell Connection in Python Tutorial

python

Secure Shell Connection in Python tells the host to which the connection needs to be established username username required to access the host Parameter Usage hostname This parameter tells the host to which the connection needs to be established username username required to access the host port host port password password for the account ssh … Read more

Python Security And Cryptography Tutorial

Python Tutorials

Python is a popular programming language has great potential in security and cryptography. Learn more about Python Security and Cryptography here. This topic deals with the cryptographic features and implementations in Python from its uses in computer and network security to hashing and encryption/decryption algorithms. Python Security and Cryptography: Secure Password Hashing The PBKDF2 algorithm … Read more

Performance Optimization In Python Tutorial

Performance optimization in Python can be done by following difference methods. Learn more about this aspect of python programming here. Performance optimization in Python: Code profiling First and foremost you should be able to find the bottleneck of your script and note that no optimization can compensate for a poor choice in data structure or … Read more

Python Speed Of Program Tutorial

python

Python speed of program can be evaluated and tested by various means. This guide tells you how to check speed of deque operations and other programs in python. Deque operations A deque is a double-ended queue. class Deque:def init(self):self.items = []def isEmpty(self):return self.items == []def addFront(self, item):self.items.append(item)def addRear(self, item):self.items.insert(0,item)def removeFront(self):return self.items.pop()def removeRear(self):return self.items.pop(0)def size(self):return len(self.items)Operations … Read more

Profiling in Python Tutorial

python

Profiling in Python is another important parameter used by different programmers in performing different tasks. Learn more about it here. Profiling in Python: %%timeit and %timeit in IPython Profiling string concatenation: In [1]: import stringIn [2]: %%timeit s=””; long_list=list(string.ascii_letters)50 ….: for substring in long_list: ….: s+=substring ….: 1000 loops, best of 3: 570 us per … Read more

Py.test in Python Tutorial

python

py.test in Python is one of several third party testing libraries that are available for Python. It can be installed using pip with many other codes. Learn more here. py.test in Python: Setting up py.test py.test is one of several third party testing libraries that are available for Python. It can be installed using pip … Read more

Python Common Pitfalls Tutorial

python

Python does have a few corner cases where it might do something different than what you were expecting. This section will show you some Python common pitfalls. Python is a language meant to be clear and readable without any ambiguities and unexpected behaviors. Unfortunately, these goals are not achievable in all cases. Python common pitfalls: … Read more

Python Hidden Features Tutorial

python

Python Hidden Features are a set of different functions which can be performed by manipulating different objects in Python. Learn more here. Python Hidden Features: Operator Overloading Everything in Python is an object. Each object has some special internal methods which it uses to interact with other objects. Generally, these methods follow the action naming … Read more

Python Unit Testing Tutorial

python

Python Unit Testing is another important parameter used by different programmers in performing different tasks. Learn more about it here. Python Unit Testing: Test Setup and Teardown within a unittest.TestCase Sometimes we want to prepare a context for each test to be run under. The setUp method is run prior to each test in the … Read more

Python Writing Extensions Tutorial

Python Writing extensions help in performing different functions with ease. As a programmer, you can learn about these extensions here. Python Writing extensions: Hello World with C Extension The following C source file (which we will call hello.c for demonstration purposes) produces an extension module named hello that contains a single function greet(): include include … Read more

Python CTypes Tutorial

python

Python ctypes is a python built-in library that invokes exported functions from native compiled libraries. Learn More about it here. Note: Since this library handles compiled code, it is relatively OS dependent. ctypes arrays As any good C programmer knows, a single value won’t get you that far. What will really get us going are … Read more

Python Serial Communication (Pyserial) Tutorial

python

Python Serial Communication (pyserial) enables manipulation of many other functions in Python programming language. Learn more here. parameter detailsport Device name e.g. /dev/ttyUSB0 on GNU/Linux or COM3 on Windows.baudrate baudrate type: int default: 9600 standard values: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,4800, 9600, 19200, 38400, 57600, 115200 Python Serial Communication … Read more

Neo4j And Cypher Using Py2Neo Tutorial

Neo4j and Cypher using Py2Neo can be done by using python programming language. Learn more about this useful function in this guide. Neo4j and Cypher using Py2Neo: Adding Nodes to Neo4j Graph results = News.objects.todays_news()for r in results:article = graph.merge_one(“NewsArticle”, “news_id”, r)article.properties[“title”] = results[r][‘news_title’]article.properties[“timestamp”] = results[r][‘news_timestamp’]article.push()[…] Adding nodes to the graph is pretty simple,graph.merge_one is … Read more

How To Call Python From C# Program Tutorial

The documentation provides a sample implementation of the inter-process communication between C# and Python scripts. Learn about Call Python from C# here. Call Python from C#: Python script to be called by C# application import sysimport jsonload input arguments from the text file filename = sys.argv[ 1 ]with open( filename ) as data_file: input_args = … Read more

Basic Curses With Python Tutorial

It is important to understand Basic Curses with Python which is another important aspect of python programming. Learn more about it here. Basic Curses with Python: The wrapper() helper function While the basic invocation above is easy enough, the curses package provides the wrapper(func, …) helper function. The example below contains the equivalent of above: … Read more