Posts

Showing posts from January, 2021

Digital Marketing

Using #Windows startup folder to launch scripts

Open the Run dialog with WindowsKey+R and enter shell:startup. Startup folder for user and global: %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup %ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp

WSL starting directory on Windows Terminal

Example: { " guid " : " {07b52e3e-de2c-5db4-bd2d-ba888ed6c888} " , " hidden " : false , " name " : " Ubuntu-20.04 " , " source " : " Windows.Terminal.Wsl " , " startingDirectory " : " C: \\ Users/goyuninfo/OneDrive " }

You can launch Windows terminal in a specific configuration by using the wt.exe command.

Install cron on #Linux

Install the latest version of a module and its dependencies from the #Python Packaging Index

python -m pip install SomePackage

The #Python Package Index (PyPI) is a repository of software for the Python programming language.

PyPI helps you find and install software developed and shared by the Python community. The Python Packaging Index is a public repository of open source licensed packages made available for use by other Python users.

A #Python virtual environment is a semi-isolated Python environment that allows packages to be installed for use by a particular application, rather than being installed system wide.

Starting with #Python 3.4, pip is included by default with the Python binary installers.

A #Bash here document is a special-purpose code block.

A #Bash here document uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor. COMMAND <<InputTagHERE ... ... ... InputTagHERE

A zero return value from the script upon exit indicates success to the #Bash shell

Check if in right directory on Linux

cd $MY_DIR if [ `pwd` != "$MY_DIR" ] # or if [ "$PWD" != "$MY_DIR" ] # Not in the right directory then echo "Can't change to $MY_DIR." exit $E_XCD #E_XCD=86 fi

Only users with $UID 0 have root privileges on #Linux

Clean up a file in Bash shell

cat /dev/null > file_to_clean_up.

Enable Copy on Select in Windows Terminal

Adding the following line to the global defaults area of your settings file. "copyOnSelect": true,

Mysql workbench prerequisites

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads Download the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 . The following updates are the latest supported Visual C++ redistributable packages for Visual Studio 2015, 2017 and 2019. Included is a baseline version of the Universal C Runtime see MSDN for details. x86: vc_redist.x86.exe x64: vc_redist.x64.exe ARM64: vc_redist.arm64.exe The following prerequisites are available at the Microsoft Download Center : Microsoft .NET Framework Microsoft Visual C++ Redistributable for Visual Studio

Get wsl version on Windows 10

> wsl -l -v   NAME            STATE           VERSION * Ubuntu-20.04    Running         1

Change the #Python default version in #Ubuntu

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1 update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode

The most effective way to run an alternative version of #Python is within a virtual environment (venv).

There is no reason to remove older versions of python as there may be scripts on the operating system which require their presence. 

Fixed Microsoft Edge’s Downloading Proxy Script issue

Open your computer’s proxy Settings Uncheck “Automatically detect Settings”

A #proxy or Proxy Server acts as a gateway between the Internet and the local network.

Identifying and removing unused #indexes is a best practice that should be performed on a regular basis on your #database.

#Database Transaction Best Practices

Keep transactions to the smallest number of commands needed. If you have transactions with multiple statements that can be divided up into multiple smaller transactions, it is advisable to do so to reduce the likelihood of a timeout. Always aim to create short transactions, not long-running reads. Always commit or abort the transaction after it is complete. Leaving a transaction in an incomplete state ties up database resources and can cause write conflicts.

#Database Transactions

Transactions simplify application development by enabling you to perform atomic, consistent, isolated, and durable (ACID) operations across one or more database instances within an cluster.

MongoDB show databases

Use show dbs command from mongo shell to list all the available databases on MongoDB server. This will show the database name with there size. rs0:PRIMARY> show dbs rs0:PRIMARY> 

AWS cli get the current region

aws configure get region will get you the current region at that point in your script. If you are using a profile, then type aws configure get --profile $PROFILE_NAME.

Always use var or let to declare #JavaScript variables.

MySQL Example Databases

sakila database TGZ | Zip View US Ltr | A4 employee data (large dataset, includes data and test/verification suite) GitHub View US Ltr | A4

Swap two MySQL table names

Make sure that a table with the intermediary name tmp_table does not already exist: RENAME TABLE old_table TO tmp_table,              new_table TO old_table,              tmp_table TO new_table;

Simhash is useful #hash function when you want to check for similar items.

Dijkstra’s algorithm is used to calculate the shortest path for a weighted #graph.

Breadth-first search is used to calculate the shortest path for an unweighted #graph.

You can’t use negative-weight edges with Dijkstra’s #algorithm.

Listing Stored Procedures from Databases in the MySQL Server

To show all stored procedures of a particular database, you use the following query:  SELECT routine_name FROM information_schema.routines WHERE routine_type = 'PROCEDURE' AND routine_schema = '<database_name>'; 

Fedora official EPEL repository

For the open EPEL repository, run the commands: sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm Accept installation when prompted.

Enable the EPEL Repository on Oracle Linux 8

sudo vim /etc/yum.repos.d/ol8-epel.repo  Paste the contents below into the file. [ol8_developer_EPEL] name= Oracle Linux $releasever EPEL ($basearch) baseurl=https://yum.oracle.com/repo/OracleLinux/OL8/developer/EPEL/$basearch/ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle gpgcheck=1 enabled=1

MySQL benchmark

SELECT benchmark(50000000,(1234*5678/37485-1298+8596^2)); #should take less than 20 seconds mysql> SELECT benchmark(50000000,(1234*5678/37485-1298+8596^2)); +---------------------------------------------------+ | benchmark(50000000,(1234*5678/37485-1298+8596^2)) | +---------------------------------------------------+ | 0 | +---------------------------------------------------+ 1 row in set (13.11 sec)

Configuration to Log all MySQL dead locks

SET GLOBAL innodb_print_all_deadlocks = 'ON'; The option is dynamic, and can be enabled without a service restart.   If you want to make it persistent after a service restart, you may want to add it to the my.cnf file as: [mysqld] ... ... innodb_print_all_deadlocks = 1

How to get Active Transactions and Dead Locks from MySQL

To get a list of active transactions and locks that are currently executing against our target database Simply use: SELECT waiting_trx_id, waiting_pid, waiting_query, blocking_trx_id, blocking_pid, blocking_query FROM sys . innodb_lock_waits ; If a NULL value is reported for the blocking query, see Identifying a Blocking Query After the Issuing Session Becomes Idle .  For MySQL 8, use  performance_schema SELECT r . trx_id waiting_trx_id, r . trx_mysql_thread_id waiting_thread, r . trx_query waiting_query, b . trx_id blocking_trx_id, b . trx_mysql_thread_id blocking_thread, b . trx_query blocking_query FROM performance_schema . data_lock_waits w INNER JOIN information_schema . innodb_trx b ON b . trx_id = w . blocking_engine_transaction_id INNER JOIN information_schema . innodb_trx r ON r . trx_id = w . requesting_engine_transaction_id ; MySQL captures transaction and lock information in the INNODB_TRX, INNODB_LOCKS, and IN

Verify #MySQL plugin installation

Examine the MySQL INFORMATION_SCHEMA.PLUGINS table or use the SHOW PLUGINS statement. mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS PLUGIN_NAME PLUGIN_STATUS binlog ACTIVE mysql_native_password ACTIVE sha256_password ACTIVE CSV ACTIVE MEMORY ACTIVE InnoDB ACTIVE INNODB_TRX ACTIVE INNODB_LOCKS ACTIVE INNODB_LOCK_WAITS ACTIVE INNODB_CMP ACTIVE INNODB_CMP_RESET ACTIVE INNODB_CMPMEM ACTIVE INNODB_CMPMEM_RESET ACTIVE INNODB_CMP_PER_INDEX ACTIVE INNODB_CMP_PER_INDEX_RESET ACTIVE INNODB_BUFFER_PAGE ACTIVE INNODB_BUFFER_PAGE_LRU ACTIVE INNODB_BUFFER_POOL_STATS ACTIVE INNODB_TEMP_TABLE_INFO ACTIVE INNODB_METRICS ACTIVE INNODB_FT_DEFAULT_STOPWORD ACTIVE INNODB_FT_DELETED ACTIVE INNODB_FT_BEING_DELETED ACTIVE INNODB_FT_CONFIG ACTIVE INNODB_FT_INDEX_CACHE ACTIVE INNODB_FT_INDEX_TABLE ACTIVE INNODB_SYS_TABLES ACTIVE INNODB_SYS_TABLESTATS ACTIVE INNODB_SYS_INDEXES ACTIVE INNODB_SYS_COLUMNS ACTIVE INNODB_SYS_FIELDS ACTIVE INNODB_SYS_FOREIGN ACTIVE INNODB_SYS_F

If the #MySQL audit log plugin is enabled, it exposes several system variables that permit control over logging

mysql> SHOW VARIABLES LIKE 'audit_log%'; +-----------------------------+--------------+ | Variable_name | Value | +-----------------------------+--------------+ | audit_log_buffer_size | 1048576 | | audit_log_compression | NONE | | audit_log_connection_policy | ALL | | audit_log_current_session | OFF | | audit_log_encryption | NONE | | audit_log_exclude_accounts | | | audit_log_file | audit.log | | audit_log_filter_id | 49 | | audit_log_flush | OFF | | audit_log_format | NEW | | audit_log_include_accounts | | | audit_log_policy | ALL | | audit_log_read_buffer_size | 32768 | | audit_log_rotate_on_size | 0 | | audit_log_statement_policy | ALL | | audit_log_strategy | ASYNCHRONOUS | +-----------------------------+--------------+

Dijkstra's #algorithm doesn’t work for graphs that have negative edges.

The Bellman-Ford algorithm, however, works for graphs that have negative edges.

The #tree is one of the most utilized complex data structure types.

The study of #algorithms is concerned with both correctness and performance

Big O Notation ignores constants.

A binary heap satisfies the heap property. The binary heap can be max or min-heap

A binary heap is a complete binary tree.  In a complete binary tree, all the levels except the last level are completely filled. At the last level, the keys are as far as left as possible.

Max-Heap vs Min-Heap

Max-Heap: In a Max-Heap the root node key is the greatest of all the keys in the heap. It should be ensured that the same property is true for all the subtrees in the heap recursively. Min-Heap: In the case of a Min-Heap, the root node key is the smallest or minimum among all the other keys present in the heap. As in Max heap, this property should be recursively true in all the other subtrees in the heap.

Python heappushpop vs heapreplace

heappushpop(heap, ele) :- This function combines the functioning of both push and pop operations in one statement. Heap order is maintained after this operation. heapreplace(heap, ele) :- This function also inserts and pops element in one statement, but element is first popped, then the element is pushed.i.e, the value larger than the pushed value can be returned. heapreplace() returns the smallest value originally in heap regardless of the pushed element as opposed to heappushpop(). You can think of heapreplace as headpoppush just for remembering it.

Python example code of heap data structure

[ec2-user@dockers git]$ python heap-example.py The created heap is : [2, 5, 9, 6, 8] The modified heap after push is : [2, 5, 3, 6, 8, 9] The popped and smallest element is : 2

Heap data structure is mainly used to represent a priority queue.

 In Python, it is available using “ heapq ” module.