Posts

set up jest for your typescript project and how to import txt files in your unit tests

Image
  Getting Started These instructions will get you setup to use  ts-jest  in your project. For more detailed documentation, please check  online documentation . using npm using yarn Prerequisites npm i -D jest typescript yarn add --dev jest typescript Installing npm i -D ts-jest @types/jest yarn add --dev ts-jest @types/jest Creating config npx ts-jest config:init yarn ts-jest config:init Running tests npm t  or  npx jest yarn test  or  yarn jest to import txt file as string, via jest-raw-loader /** @type { import('ts-jest/dist/types').InitialOptionsTsJest } */ module . exports = { preset : ' ts-jest ' , testEnvironment : ' node ' , " transform " : { " \\ .txt$ " : " jest-raw-loader " } }; or follow https://nextjs.org/docs/testing if you are using next.js https://www.npmjs.com/package/jest-raw-loader https://github.com/kulshekhar/ts-jest https://jestjs.io/zh-Hans/docs/getting-started https://jestjs.io/docs/configu

Import txt files as string into your next.js App

Image
 import file from './xxx.txt' Webpack 5 has 'Asset Modules' to allow you to import assets without configuring loaders now. Next.js use Webpack 5 internally, so we can use 'source assets' to import txt files as strings. Two steps to let you be able to import a txt file as a string. custom Webpack config for next.js config . module . rules . push ({ test : / \. txt $ / i , type : ' asset/source ' }) declare txt as a module for typescript Wildcard module declarations can be used to cover these cases. declare module ' *.txt ' { const content : string ; export default content ; } example import t1 from ' ./1.txt ' console . log ( t1 ) output event - compiled successfully 离开罪之路的人蒙祝福, 他不去随从恶人的计谋, 他不会站在罪人的道路上, 也不去坐好讥笑人的座位, 他喜爱的是耶和华律法, 昼夜默诵的也是他律法。 The full commit to enabling import txt files in your next.js app references

How to Use SODA for REST with OAuth Client Credentials in your Node.js/Web App to CRUD Oracle Autonomous Database?

Image
Use SODA for REST with OAuth Client Credentials in your Node.js or Web application to CRUD Oracle Autonomous Database

How to Create ads.txt for your Ghost blog website

Image

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