Categories
Mastering Development

Vectorized Pandas method for set-like comparison against multiple boolean columns/series

Sample data to illustrate: import pandas as pd animals = pd.DataFrame({‘name’: [‘ostrich’, ‘parrot’, ‘platypus’], ‘legs’: [2, 2, 4], ‘flight’: [False, True, False], ‘beak’: [True, True, True], ‘feathers’: [True, True, False]}) name legs flight beak feathers ostritch 2 ✔ ✔ parrot 2 ✔ ✔ ✔ platypus 4 ✔ What already works Pandas makes it easy to […]

Categories
Mastering Development System & Network

Changing collation of all tables and columns in MySQL

I tried to do this: https://serverfault.com/a/65572/603515 But I changed it slightly to target only the database I want to change. mysql -B -N –host=localhost –user=root –password=secret -e "select CONCAT(‘alter table ‘,TABLE_SCHEMA,’.’,TABLE_NAME,’ charset=utf8mb4_bin;’) from information_schema.TABLES WHERE TABLE_SCHEMA = ‘usda_nndsr’; select CONCAT(‘alter table ‘,TABLE_SCHEMA,’.’,TABLE_NAME,’ alter column ‘,COLUMN_NAME,’ charset=utf8mb4_bin;’) from information_schema.COLUMNS WHERE TABLE_SCHEMA =’usda_nndsr’;" | mysql –host=localhost –user=root […]

Categories
Database Development

AWS DMS ‘inventing’ data rows?

I have been testing AWS’ DMS for a while, considering a move from MySQL on EC2 to Aurora serverless, and I have observed several times that extra rows are inserted into certain tables; always the same tables, it seems. I first noticed it because I ran a procedure to check all foreign keys – here’s […]

Categories
Database Development

Can’t use \G in a handler?

I have a slightly annoying problem. This is on AWS Aurora Serverless – I have found a stored procedure somewhere for checking foreign keys, and modified it a little, adding a handler for 1146: DELIMITER $$ DROP PROCEDURE IF EXISTS ANALYZE_INVALID_FOREIGN_KEYS$$ CREATE PROCEDURE `ANALYZE_INVALID_FOREIGN_KEYS`( checked_database_name VARCHAR(64), checked_table_name VARCHAR(64), temporary_result_table ENUM(‘Y’, ‘N’)) LANGUAGE SQL NOT DETERMINISTIC […]

Categories
CMS Mastering Development Wordpress

Allow users to change their role except for the roles I choose

This function displays a check list and allows all users to edit their user role/s to any others in the backend user profile backend, including admin etc. How would I exclude certain roles from the list? function mrpu_plugin_init() { load_plugin_textdomain(‘multiple-roles-per-user’, false, dirname(plugin_basename(__FILE__)) . ‘/languages/’); } add_action(‘plugins_loaded’, ‘mrpu_plugin_init’); function mrpu_admin_enqueue_scripts($handle) { if (‘user-edit.php’ == $handle) { […]

Categories
Mastering Development

I have made a login system, however, I don’t know how to style some of it

So, I have been working on a login page, and it has been working beautifully so far. However, I cannot style where the error message appears. Here is the code: — The login.php file — <?php include_once ‘../resources/session.php’; include_once ‘../resources/database.php’; include_once ‘../resources/utilities.php’; if(isset($_POST[‘loginBtn’])){ // array to hold errors $form_errors = array(); // validate $required_fields = […]

Categories
CMS Mastering Development Wordpress

Admin user column sort by numeric meta key

I try to sort a custom user field (team_user_id), I have all data but I can’t sort by numeric. updated code add_filter(‘manage_users_columns’, [$this, ‘custom_id_column’]); add_filter(‘manage_users_custom_column’, [$this, ‘custom_id_content’], 10, 3); add_filter(‘pre_get_posts’, [$this, ‘sort_content’]); public function custom_id_column($columns) { foreach ($columns as $k => $v) { if ($k === ‘username’) { $new_columns[‘ID’] = __(‘ID’, ‘default’); } $new_columns[$k] = […]

Categories
Linux Mastering Development

How to sort and compare 2 csv files column by column and move the difference to third file using shell scripting

file1.csv table_name,column_name,data_type common_lot,trend_date,date common_lot,context_date,date common_lot,lot_id,number file1.csv table_name,column_name,data_type common_lot,trend_date,date common_lot,context_date,number common_lot,lot_id,varchar2 Expected output is: table_name,column_name,data_type common_lot,context_date,number common_lot,lot_id,varchar2

Categories
Database Development

How to search entire database to find tables that contain 2 columns?

This database query doesn’t work: select table_schema, table_name, column_name, column_name2 from information_schema.columns where column_name = ‘user_id’ and column_name2 = ‘organisation_id’ and table_schema = ‘brand_production’; I would like to search for each table in the database to see if it contains "user_id" and "organisation_id"?

Categories
Database Development

MySQL How to Script to create indexes on all date columns in database

I have a lot of tables in the database that are using a datetime stamp – I need to create a script that will create indexes on all columns in each table that does not already have an index . So far I can get all the columns of type date, time etc.. I can […]