Skip to main content

Posts

Remove first n and last n character in huge file

JSON file often only in 1 line. To remove first n character: sed -i.bak -r '1s/^.{10}//' file https://stackoverflow.com/questions/26400118/delete-first-n-characters-of-a-very-large-file-in-unix-shell See first 50 bytes of file: head -c 50 file See last 50 bytes: tail -c 50 file remove last n character sed '$ s/.$//' somefile  # slow and not work, don't know why truncate -s-1 file # super fast https://stackoverflow.com/questions/27305177/how-can-i-remove-the-last-character-of-a-file-in-unix I use git-bash windows 10, JSON ab 3GB Why not sed The problem with a sed solution like sed '$ s/.$//' file is that it reads the whole file first (taking a long time with large files), then you need a temporary file (of the same size as the original): One more time my psychological knowledge suck. The "right" answer here is not marked right, OK but it seem better.

Mysql create user, allow access to DB, allow access DBs by prefix and wildcard

https://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-database https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql Copy, clone (duplicate) whole database: https://stackoverflow.com/questions/1887964/duplicate-entire-mysql-database CREATE DATABASE duplicateddb; Make sure the user and permissions are all in place and:  mysqldump -u admin -p originaldb | mysql -u backup -pPassword duplicateddb;  MySQL password policy validation: https://stackoverflow.com/questions/43094726/your-password-does-not-satisfy-the-current-policy-requirements?rq=1 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements It seem MySQL new (?) password validation ? I tried few password and end up with a password length about 10 character, 1 Capical, some number and a special char, something like this: Cmypass_1234 Allow access to databases by prefix and then wildcard: https://sta...

Some aha moments with Git, SVN

From source blog (link here). SVN has dry-run for know what could be change before actually run it. Git has fetch similar (?) SVN status will show both server change updated, Git only show local repository change status (since git is distributed system ?). SVN and Git have mechanism to rollback to any revision ? Sometime we have to careful to search what similar feature in alternative. Nginx has nginx -t for test configurations, what apache similar ?

WP, WC mail failed payment not sent. Payment gateway WC-Paypal, Yith-Stripe

How to test mail without wait ab 1 days, 2 days ? The problem could be in payment gateway, not only WC. https://docs.woocommerce.com/document/email-faq/ Standard Paypal troubleshoot:  https://docs.woocommerce.com/document/paypal-standard/#section-20 Is  WC Paypal is default ? Debug, not show error on site: define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false ); Log dump to wp-content/debug.log There are many useful information about sending and receive email here. For example, addition information about Gmail free account limit up to 500 unique recipient in 24h period. https://support.google.com/mail/answer/22839?hl=en https://en-gb.wordpress.org/plugins/wp-mail-logging/ wp-content/plugins/post-smtp/Postman/Postman-Mail/ wp-mail-smtp Suggested Dedicated SMTP Providers Like Mailgun (plugin), Maildrill (plugin). Use this way we can test on Dev server instead of real Hosting like WPEngine. Dev server o...

WP Cron not run without a action from user (Web client, Browser... )

I read document ab WP cron and it say something like it require user perform some action, for example access homepage, browse some item etc. If no user enter site then cron job not run. But there are many other information that confuse me. I just want to know does it run as scheduled as Native Linux cron or Windows Scheduler ? Here are test script. The basic idea is that let log timestamp of cronjob run to verify it run and in expected schedule. Add these function to one of the cronjob (often placed in functions.php or lib folder in wp-content/themes/your-theme/... add_filter( 'cron_schedules', 'add_every_min' ); function add_every_min( $schedules ) { $schedules['every_min'] = array( 'interval'  => 60, 'display'   => __( 'Every Min', 'textdomain' ) ); return $schedules; } // Schedule an action if it's not already scheduled if ( ! wp_next_scheduled( 'add_every_min' ) ) { wp_schedule_eve...

WP hook note hook action return, hook filter return ...

Return command/semantic in WP action hook is magnificent. Try dig to WP document, compare with another Callback mechanism in NodeJS to have a clearer view of it. Like Java String object/functions. There are some "weird" constructor, for example new String(byte[] bytes, int , int, String) ... https://wordpress.stackexchange.com/questions/174850/how-to-use-return-in-my-custom-function-instead-of-echo If you use do_action( 'woo_collections_menu' ); in the template, then your function must echo its value. Otherwise, you are returning the data into a black hole , nothing is outputting what you're returning. If you use a filter, then you should  return  the value. The point of a filter is to take a value, filter that value through a function, then do something with the result. In the context of your template, using  apply_filters  would be a bit strange, because your menu has no value until you construct it. So in the template it would look like: echo apply_fi...

GCP Google Cloud Platform

Gcloud SSH problem (need update) Gcloud firewall understanding and manipulate. Gcloud default domain bc.googleusercontent ... Port forwarding, proxy-pass nginx to NodeJS. Gcloud create routes https://cloud.google.com/vpc/docs/firewalls 1890  gcloud config set compute/zone asia-southeast1-a 1895  gcloud compute networks create jenkins --mode auto 1896  gcloud container clusters create jenkins-cd   --network jenkins   --scopes "https://www.googleapis.com/auth/projecthosting,storage-rw" 1897  gcloud container clusters get-credentials jenkins-cd 1899  gcloud compute images create jenkins-home-image --source-uri https://storage.googleapis.com/solutions-public-assets/jenkins-cd/jenkins-home-v3.tgz 1900  gcloud compute disks create jenkins-home --image jenkins-home-image --zone us-east1-d 1901  gcloud compute disks create jenkins-home --image jenkins-home-image --zone asia-southeast1-a 1960  gcloud help 1961  gcl...