Posts

Showing posts from 2020

How to Internationalizing your Flutter apps ?

Image
First Reading: https://flutter.dev/docs/development/accessibility-and-localization/internationalization Steps: 1. add flutter_localizations dependencies into pubspec.yaml dependencies : flutter : sdk : flutter flutter_localizations : sdk : flutter 2. add localizationsDelegates and supportedLocales into MaterialApp Applocalizations.delegate is your app-specific localization delegate. will be introduced in next step. Widget build ( BuildContext context) { return MaterialApp ( localizationsDelegates: [ AppLocalizations .delegate, GlobalMaterialLocalizations .delegate, GlobalWidgetsLocalizations .delegate, GlobalCupertinoLocalizations .delegate, ], supportedLocales: [ const Locale . fromSubtags (languageCode: 'zh' ), // generic Chinese 'zh' const Locale . fromSubtags ( languageCode: 'zh' , scriptCode: 'Hans' ), // generic simplified Chinese 'z

How to measure the maximum throughput (TPS - Transactions per Second) that a single website instance(host) can handle via curl tool ?

Image
tps.py, a python script using curl to measure the time per transaction requested to your website curl --connect-timeout 10 --max-time 10 -o /dev/null -s -w "%{http_code},%{size_download},%{time_appconnect},%{time_connect},%{time_namelookup},%{time_pretransfer},%{time_starttransfer},%{time_total}" -k #!/usr/bin/python #-*- coding: UTF-8 -*- import commands import getopt import os import re import sys import thread import threading import time def help(code):     print 'tps.py -A "useragent" -C "cookies" -H "header" -P "period" -T "tps" -U "url" -O "outputdir"'     print 'examples:'     print 'tps.py -U https://www.amazon.com -T 20 -P PT5M'     print 'tps.py -U https://www.amazon.com -T 20 -P PT1H'     sys.exit(code) def check_args(a, c, h, p, t, u, o):     if u == '':         print 'no URL specified!'         help(2)     if t == &#

Python : How to run a function "foo" per second and last a few minutes or hours

Scenario I tried to run a function "foo" every second. I have to do this for a few minutes (say 5). The function foo () sends 100 HTTP requests (including JSON objects) to the server and prints the JSON response. In short, I have to issue 100 HTTP requests per second for 5 minutes. Using threading.Timer #!/usr/bin/python import time import thread import threading def foo(): print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), threading.active_count() #5 minutes = 5 * 60 = 300 seconds for x in range(0, 300): t = threading.Timer(x + 1, foo) t.start() Expected output function foo was executed per second and last about 5 minutes 2020-05-14 00:54:49 301 2020-05-14 00:54:50 300 2020-05-14 00:54:51 299 2020-05-14 00:54:52 298 2020-05-14 00:54:53 297 2020-05-14 00:54:54 296 2020-05-14 00:54:55 295 ....... 2020-05-14 00:59:44 6 2020-05-14 00:59:45 5 2020-05-14 00:59:46 4 2020-05-14 00:59:47 3 2020-05-14 00:59:48 2

How to kill a bunch of processes which executed with almost same command ?

Scenario Sometimes we need to manually terminate the process. If not killing too many processes, it is easy to find the pid and kill it. But what if there are a bunch of processes that need to be terminated? Today I encountered such a problem, started a lot of python process, but the result can not stop. gkill Solution add below function to your bash profile, then source the profile function gkill() { ps -ef | grep ${1} | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 } Then you can kill all processes that matched your serach pattern via gkill command. gkill <search content> Extended knowledge The commands related to the termination process are: ps: report a snapshot of the current process kill: send a signal to a process killall: kill process by name pkill: View or issue process signals based on name and other attributes skill: send a signal or report the process status xkill: destroy a client program according to X resources xargs

Recommend GC log analyzer tool : GCPlot & GCeasy

Image
GCPlot Install Docker Installation You can run GCPlot in a Docker container. In order to run GCPlot as-is without additional configuration, run next command: docker run -d -p 8080:80 gcplot/gcplot After that eventually the platform will be accessible from your host machine at http://127.0.0.1:8080 address. Upload GC log JVM arguments -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCCause -XX:+PrintHeapAtGC -XX:+PrintAdaptiveSizePolicy -XX:+UnlockDiagnosticVMOptions -XX:+G1SummarizeRSetStats -XX:G1SummarizeRSetStatsPeriod=1 -Xloggc:/var/output/logs/garbagecollector.log -XX:+UseG1GC Analysis Groups Universal GC Log Analyzer https://gceasy.io/ It is more powerful than GCPlot, but you have to upload you GC logs to their backend and pay to see the analysis report. GCPlot is free and open source Fork from github https://it.gcplot.com/

English Language : 20 ways to give advice

MODALS You have to ... You'd better ... You should ... You ought to ... You could ... CONDITIONALS If I were you, I'd ... If I were in your shoes, I'd ... If you want my advise, I think ... If you really want to know, I'd ... If I were in your position, I'd ... FORMAL VERBS I suggest (that) you ... I recommend (that) you ... I urge you ... I would advise you to ... CASUAL You're gonna wanna ... You might wanna consider You should probably consider You should maybe think about ... Have you thought about ... ? What you yought do is ... ?

English Language : Adverbs of Intensity

Image
OMG SO INTENSE completely totally thoroughly absolutely perfectly extremely Utterly Kind of intense fairly rather somewhat moderately considerably nearly kind of sort of noticeable pretty intense awfully pretty really so very mostly quite ehh... a little a bit slightly Common combinations perfectly sort of bland a little hungry absolutely certain pretty sure quite good nearly exausted mostly finished noticeably different

English Language : Passive Prepositional Verbs

be aimed at The advertisement was aimed at males between the ages of 18 to 34 be associcated with Drinking milk is often associated with strong bones be based on The study was based on 10 years of close observation be regarded/seen as Albert Einstein is regarded as the premier theoretical physicist of the 20th century be defined as Darkness is defined as the absence of light be derived from Some medicines are derived from herbs be divided into Canada is divided into provinces and territories be involved in J. Robert Oppenheimer was the primary figure involved in the creation of the atomic bomb. be known as The Wright Brothers are popular known as the pioneers of humann flight be prejudiced against Human are often prejudiced againt people they do not understand be required for Regular sleep is required for good health be used in Flamethrowers were first used in WW I

English Language : Money

Level of wealth poor broke, living check to check rich loaded, well-off Spending habits cheap frugal a penny pincher Going out Wanna split the bill ? pay for someone I will cover you I will get it I got it It's on me My treat Using the ATM I need to make a withdrawal I need to withdraw some money I need to make a deposit I need to deposite some money Currency vocabulary bucks = dollars ( 10 bucks ) a grand = a thousand dollars (2 grand) $0.25 = a quarta $0.10 = a dime $0.05 = a nickel $0.01 = a penny CAD$1.00 = a loonie CAD$$2.00 = a toonie

English Language : Learn 26 adjectives to describe the taste and texture of food

FLAVORS Sweet ( sugar ) Sour ( lemon ) Bitter ( medicine ) Bland ( potatoes ) Plain Spicy ( jalapenos ) Salty ( chips ) Savory ( creamy | soups ) TASTES AND TEXTURE Crunchy Crispy ( fried food ) Mealy ( soft and sandy ) Mushy Soggy ( wet ) Juicy Fatty Oily Greasy Character Rich Decadent Heavy, Ripe

English Language : 35 words that we shorten in conversation

abdominal muscles - abs administration - admin application - app (software) fabulous - fab favourite - fave delicious - delish identification - ID information - info radical - rad (cool) comfortable - comfy advertisement - ad laboratory - lab limousine - limo maximum - max medication - meds overdose -OD referee - ref underware - undies representative - rep represent

English Language : EFFECT and CAUSE VERBS

Image
EFFECT VERBERS Cause The 2008 financial crisis caused several problems for multinational banks Produce The medication did not produce the desired effect Lead to Several international incidents led to WWII Result in The earchquake resulted in thousands of deaths Create The increasing rate of crime is creating numerous issues Bring about The new regime brought about stricter laws Give rise to The election result gave rise to public protests be responsible for No one knows who was responsible for the vandalism CAUSE VERBS be caused by The governmental collapse was caused by the implementation of unpopular policies be produced by The vast majority of air pollution in Europe is produced by fertilisers and animal waste. be brought about by Major economic benefits could be brought about by the adoption of solar roofs result from Many benefits quickly result from exercise stem from Most of our early beliefs stem from our parents be trig

How to obtain/get copied image from clipboard data in browser

Image
JS code works well for Chrome, Firefox and Safari const source = document.querySelector('.source'); source.addEventListener('paste', (event) => { if (event.clipboardData && event.clipboardData.items && event.clipboardData.items.length == 1) { const item = event.clipboardData.items[0]; if (item.kind == 'file' && item.type == 'image/png') { let blob = item.getAsFile(); let f = new FileReader(); f.onload = (e) => { console.log(e.target.result); } f.readAsDataURL(blob); } } event.preventDefault(); }); Image source to data base64 url from clipboard data