How to replace multiple characters in a string using python?
As you may already know there is a method for string called
 
But what if you want to replace both
 
Here output would be
#python #string #replace #multiple_replacement
  As you may already know there is a method for string called
replace that replaces 1 character with a new given character:'+98 21 445 54 12'.replace('+', '')
 # output is 98 21 445 54 12But what if you want to replace both
+ and [SPACE] inside of the string? The answer is simple just chain the methods:'+98 21 445 54 12'.replace('+', '').replace(' ', '')Here output would be
98214455412.#python #string #replace #multiple_replacement
  Tech C**P
How to replace multiple characters in a string using python?   As you may already know there is a method for string called replace that replaces 1 character with a new given character:  '+98 21 445 54 12'.replace('+', '')  # output is 98 21 445 54 12  But…
  Fraud Detection on credit card using Apache Kafka KSQL:CREATE TABLE possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 SECONDS)
GROUP BY card_number
HAVING count(*) > 3;
The above query creates a moving window in 5 seconds timeframe and check whether there are more than 3 authorization attempt on a
specific credit card, real time!
KSQL is a good fit for identifying patterns or anomalies on real-time data. By processing the stream as data arrives you can identify and properly surface out of the ordinary events with millisecond latency.
#apache #kafka #ksql #fraud_detection
How to check whether a socks server working or not?
Let's say you have run a socks server on port 8888. Now in order to test the server, you just need to use
 
If you see some
 
The above error says that port 8888 is not available, you may see different errors based on the server configuration stat. Hope it helps.
#socks5 #socks #socks_server #curl
  Let's say you have run a socks server on port 8888. Now in order to test the server, you just need to use
cURL! You need to provide --socks5 parameter to cURL as below:curl --socks5 localhost:8888 binfalse.de
If you see some
HTML stuff, your server is up & running, but if you see the below error it      seems the server is not working properly:curl: (7) Failed to connect to localhost port 8888: Connection refused
The above error says that port 8888 is not available, you may see different errors based on the server configuration stat. Hope it helps.
#socks5 #socks #socks_server #curl
If you are working in docker and have utf8 problems like 
 
 
#python #encoding #utf8 #encode #decode
  UnicodeDecodeError exceptions. And you are scratching your head like me and encode & decode does no good for the problem, use setdefaultencoding:import sys
reload(sys)
sys.setdefaultencoding("utf-8")
NOTE: it is discouraged to use the above function. As I have mentioned docker which its OS is isolated, I aware of what I'm doing. In case you are in doubt DO NOT USE IT specially on host OS!#python #encoding #utf8 #encode #decode
As you may remember we have explained 
Today we are gonna give a python example of the
 
I prefer not to clutter the post by pasting the whole script here. :)
 
module which causes
 
 
Usecases are endless! You can use as part of messaging infrastructure in your microservice environment or as a chat system, you name it! :)
#python #redis #pubsub #publish #subscribe #thread
  redis pubsub in which someone subscribe to a specific channel and then another console         publish messages to that channel. The publisher has no idea who is listening on the other side, it just publish messages which is      received.Today we are gonna give a python example of the
redis pubsub using threading and redis python module. Take a look at the code    in the link below:https://gist.github.com/alirezastack/ff2515cc434360f544d8a9341155947e
I prefer not to clutter the post by pasting the whole script here. :)
subscribe method is used to subscribe to a given channel, here it is called test. start method is used as part of the threadingmodule which causes
run method to be called. Both run and start is Thread super class methods. When you run the script it      will subscribe to test channel and wait for new messages.NOTE: you can publish to test channel in redis console (`redis-cli`) as below:127.0.0.1:6379> publish test hello_python
(integer) 1
Usecases are endless! You can use as part of messaging infrastructure in your microservice environment or as a chat system, you name it! :)
#python #redis #pubsub #publish #subscribe #thread
Executing 
In
 
 
If you are already running mysql, you can execute an SQL script file using the source command or \. command:
 
#mysql #execute #command #statement
  MySQL statements from a text file:In
MySQL it is possible to put your SQL statements in a file and then tell mysql to read its input from that file. To do so, create a text file text_file that  contains the statements you wish to execute. Then invoke mysql as shown here:shell> mysql db_name < text_file
NOTE: If you place a USE db_name statement as the first statement in the file, it is unnecessary to specify the database name on the command line.If you are already running mysql, you can execute an SQL script file using the source command or \. command:
mysql> source file_name
#mysql #execute #command #statement
How to add color to your logs in 
It's easy as pie, just install
 
By default the
If you don't want to see log messages from libraries, you can pass a specific logger object to the
 
#log #logger #coloredlogs #logging #color
  python?It's easy as pie, just install
coloredlogs with pip and then:import coloredlogs, logging
logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG')
# Some examples.
logger.debug("this is a debugging message")
logger.info("this is an informational message")
logger.warning("this is a warning message")
logger.error("this is an error message")
logger.critical("this is a critical message")
By default the
install() function installs a handler on the root logger, this means that log messages from your code and log         messages from the libraries that you use will all show up on the terminal.If you don't want to see log messages from libraries, you can pass a specific logger object to the
install() function. In this case  only log messages originating from that logger will show up on the terminal:coloredlogs.install(level='DEBUG', logger=logger)
#log #logger #coloredlogs #logging #color
In designing API SDKs and documentation it is really annoying to put a whole lot of time to design the documentation and/or designing  SDKs in different languages! How do you create SDKs for C#, python, Go, .NET, etc when you are limited in resources? IT world has      gone so far, that creation of 
As well as other programs or languages it needs some specification that all needs to follow.
What is
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.
One of the great editors for designing the spec is
- https://editor.swagger.io/
The full open specification of
- https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md
I should again note that this is a wonderful spec and makes your life easier if you master the specification. A sample documentation of
- https://docs.alopeyk.com/
#openapi #swagger #spec #restful #api #alopayk
  
  SDKs for the API or creation of documentation (with great web UI) have been made automatic. No one     need to interfere in between.As well as other programs or languages it needs some specification that all needs to follow.
OpenAPI is the thing!What is
OpenAPI?The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.
One of the great editors for designing the spec is
swagger live editor:- https://editor.swagger.io/
The full open specification of
OpenAPI 3.0:- https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md
I should again note that this is a wonderful spec and makes your life easier if you master the specification. A sample documentation of
OpenAPI is Alopayk:- https://docs.alopeyk.com/
#openapi #swagger #spec #restful #api #alopayk
GitHub
  
  OpenAPI-Specification/versions/3.0.0.md at main · OAI/OpenAPI-Specification
  The OpenAPI Specification Repository. Contribute to OAI/OpenAPI-Specification development by creating an account on GitHub.
  Did you know that you can monitor redis commands live from within 
Go to redis client by typing
 
It will log everything that happens on your redis server.
#redis #redis_cli #cli #monitor
  redis-cli console?Go to redis client by typing
redis-cli in terminal and then type monitor command and enter:127.0.0.1:6379> monitor
OK
1514301845.678553 [0 127.0.0.1:59388] "COMMAND"
1514301859.676761 [0 127.0.0.1:59388] "HSET" "user" "name" "ali"
It will log everything that happens on your redis server.
#redis #redis_cli #cli #monitor