Skip to main content

Posts

Showing posts from June, 2018

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...

Stripe YITH-WC Credit Card

https://blog.launchdarkly.com/best-practices-for-testing-stripe-webhook-event-processing/ It seem that case many webhook is rarely happened and can be avoid easily by simple remove test site webhook ? Update the user’s credit card to be one that will fail to charge (4000000000000341 is the test card number that Stripe provides for this purpose). Test expected payment status: https://stripe.com/docs/testing  on Testing status response section For test webhook https://ngrok.com/ https://github.com/bubenshchykov/ngrok See how to build a module  https://github.com/nijikokun/stripe-mock-webhooks/blob/master/index.js https://www.masteringmodernpayments.com/stripe-webhook-event-cheatsheet 11. Invoice charge attempt succeeds The normal course of events with a subscription is that the invoice is paid properly and on time. Stripe will send an `invoice.created` event one hour before attempting to pay the invoice, which gives you time to add items to the invoice for balanc...

Note Mecurial hg commands

Try hg manipulate delete branch merge fix conflict on a test repo  https://bitbucket.org/dungnv_NAL/ ... Clean, remove all change (not pushed). hg update -C -r 123 hg revert hg pull, update ... hg log -p -r 2581 List change in revision 2581 with its parent. hg diff -r 111 -r 222 (Not tested yet) hg checkout/revert back to old revision hg update -r REV merge: hg merge hg commit --close-branch https://stackoverflow.com/questions/4957721/mercurial-how-to-discard-all-local-changes-including-to-unversioned-files sudo hg status --change 8f20236cba39 https://stackoverflow.com/questions/13112280/mercurial-hg-equivalent-of-git-reset-mixed-or-soft hg status --change REV sudo hg revert ../../../wp-config.php sudo hg rollback sudo hg merge sudo hg update default # Abort hg commit # r = revision number get by `hg log --limit=5` hg update -C -r 3 # reset commit not pushed #similar as git reset hard ... hg strip --keep --rev . # In case same branch f...

Note Win 8 Eclipse J2ME dev

Eclipse Version: Helios Service Release 1 Build id: 20100917-0705 eclipse-jee-helios-SR1-win32.zip Java JDK OS: Windows 8.1 Pro N x64 Java JDK, JRE: Version 8 update 73 ( build 1.8.0_73-b02 ) Both User/System JRE: C:\Program Files\Java\jre1.8.0_73\bin\javaw.exe Platform Product 1.8 1.8.0_73 http://java.sun.com/products/autodl/j2se C:\Program Files\Java\jre1.8.0_73\bin\javaw.exe true file:///C:/WTK2.5.2_01/index.html Welcome to the Sun Java Wireless Toolkit for CLDC. The version 2.5.2 release is available on both Windows and Linux platforms. The product documentation discusses both platforms. Sun Java Wireless Toolkit Version 2.5.2_01 for CLDC is a Security Update that corrects vulnerabilities that might allow an untrusted application to execute arbitrary code. This can only happen if you obtain a malicious program and run it in an earlier version of the toolkit. The only change between version 2.5.2_01 and version 2.5.2 is the security update, so referen...