Collage

n. A piece of art made by sticking various different materials, aka PHENOMENA Magazine
Department
programming

programming

How to include only needed modules in pyinstaller?
For this you need to create a separate environment, because currently you are reading all the modules you have installed on your computer. To create environment run commands 1 - if you don't have one, create a requirements.txt file that holds all packages that you are using, you could create one with: pip freeze > requirements.txt 2 - create env folder: python -m venv projectName 3 - activate the environment: source projectName/bin/activate 4 - install them: pip install -r requirements.txt alternatively if you know you are using only wxpython you could just pip install wxpython 5 - then finally you can run pyinstaller on your main script with the --path arg as explained in this answer: pyinstaller --paths projectName/lib/python3.7/site-packages script.py   How to include only needed modules in pyinstaller? I'm using pyinstaller to generate an .exe file for my single python file, but the size is more than 30MB and the startup is very slow. From what I have gathered is that pyinstaller by default bundl... https://stackoverflow.com/questions/55312146/how-to-include-only-needed-modules-in-pyinstaller  
python · Feb. 23, 2023, 8:36 p.m.
How do I determine the total size of a directory (folder) from the command line?
The command du "summarizes disk usage of each FILE, recursively for directories," e.g., du -hs /path/to/directory -h is to get the numbers "human readable", e.g. get 140M instead of 143260 (size in KBytes) -s is for summary (otherwise you'll get not only the size of the folder but also for everything in the folder separately) As you're using -h you can sort the human readable values using du -h | sort -h The -h flag on sort will consider "Human Readable" size values. If want to avoid recursively listing all files and directories, you can supply the --max-depth parameter to limit how many items are displayed. Most commonly, --max-depth=1 du -h --max-depth=1 /path/to/directory   How do I determine the total size of a directory (folder) from the command line? Is there a simple command to display the total aggregate size (disk usage) of all files in a directory (folder)? I have tried these, and they don't do what I want: ls -l, which only displays the ... https://askubuntu.com/questions/1224/how-do-i-determine-the-total-size-of-a-directory-folder-from-the-command-line  
server · Feb. 7, 2023, 11:44 p.m.
linux Ubuntu filesystem
Run multiple Elasticsearch instances on one server using Docker
<Without docker-compose.yml> 1. Install Docker 2. Elasticsearch 7.16.2 2-1. Install Elasticsearch # docker pull docker.elastic.co/elasticsearch/elasticsearch:7.16.2 2-2. Execute Elasticsearch # docker run -d -p 9200:9200 -p 9300:9300 --name es_x -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e ES_JAVA_OPTS="-Xms200m -Xmx200m" docker.elastic.co/elasticsearch/elasticsearch:7.16.2 8fd1161fed14b8e048e0f929a37cfacbab56371dc4c2b134602469c321cc0421 2-3. Check Execution # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8fd1161fed14 docker.elastic.co/elasticsearch/elasticsearch:7.16.2 "/bin/tini -- /usr/l…" 45 seconds ago Up 43 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es_x 2-4. Check your Elasticsearch settings # docker exec -i -t es_x cat /usr/share/elasticsearch/config/elasticsearch.yml cluster.name: "docker-cluster" network.host: 0.0.0.0 2-5. Stop # docker stop es_x es_x   <With docker-compose.yml> 1. See up to and including Item 2-1. 2. docker-compose.yml version: '3.6' services: elasticsearch: image: 'docker.elastic.co/elasticsearch/elasticsearch:7.16.2' container_name: es_a ports: - 9200:9200 environment: - node.name="es_a" - cluster.name="es-docker-cluster" - bootstrap.memory_lock=true - discovery.type=single-node #- "ES_JAVA_OPTS=-Xms200m -Xmx200m" volumes: - ./esdata:/usr/share/elasticsearch/data - ./eslog:/usr/share/elasticsearch/log ulimits: memlock: soft: -1 hard: -1 networks: - elastic deploy: resources: limits: memory: 1GB # Use at most 50 MB of RAM elasticsearch2: image: 'docker.elastic.co/elasticsearch/elasticsearch:7.16.2' container_name: es_b ports: - 9201:9200 environment: - node.name="es_b" - cluster.name="es-docker-cluster2" - bootstrap.memory_lock=true - discovery.type=single-node #- "ES_JAVA_OPTS=-Xms200m -Xmx200m" volumes: - ./esdata2:/usr/share/elasticsearch/data - ./eslog2:/usr/share/elasticsearch/log ulimits: memlock: soft: -1 hard: -1 networks: - elastic2 deploy: resources: limits: memory: 1GB # Use at most 50 MB of RAM volumes: esdata: driver: local driver_opts: o: bind type: none #device: /data esdata2: driver: local driver_opts: o: bind type: none #device: /data2 eslog: driver: local eslog2: driver: local networks: elastic: driver: bridge elastic2: driver: bridge # docker-compose -f docker-compose.yml up -d # docker-compose -f docker-compose.yml stop # docker-compose -f docker-compose.yml rm 3. Result # docker-compose -f docker-compose.yml up -d [+] Running 2/2 - Container es_a Started 2.1s - Container es_b Started # docker-compose -f docker-compose.yml stop [+] Running 2/2 - Container es_a Stopped 1.2s - Container es_b Stopped 3-1. 9200 { "name" : "\"es_a\"", "cluster_name" : "\"es-docker-cluster\"", "cluster_uuid" : "KwFTIgGCT7e8ZDNJIau6Jw", "version" : { "number" : "7.16.2", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb", "build_date" : "2021-12-18T19:42:46.604893745Z", "build_snapshot" : false, "lucene_version" : "8.10.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } 3-2. 9201 { "name" : "\"es_b\"", "cluster_name" : "\"es-docker-cluster2\"", "cluster_uuid" : "MZhKEnPuTdu5iNoatWOnQA", "version" : { "number" : "7.16.2", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb", "build_date" : "2021-12-18T19:42:46.604893745Z", "build_snapshot" : false, "lucene_version" : "8.10.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }   * If error raised 'Custom Analyzer [nori_korean] failed to find tokenizer under name [nori_tokenizer]' Install Korean (nori) Analysis Plugin # sudo bin/elasticsearch-plugin install analysis-nori The plugin must be installed on every node in the cluster, and each node must be restarted after installation.   * Cannot bind to some ports due to permission denied Run as admin: net stop winnat net start winnat   Ref. Docker bind elasticsearch volume in app folder I have the following docker-compose file : version: "3.3" services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1 volumes: - esdata:/usr/share/ https://stackoverflow.com/questions/52373356/docker-bind-elasticsearch-volume-in-app-folder Docker, running multiple container (elasticsearch) I'm running one elasticsearch with version: '3' services: elasticsearch: build: context: . dockerfile: ./compose/elasticsearch/Dockerfile args: - VERSION=${VERSION} - M... https://stackoverflow.com/questions/59500443/docker-running-multiple-container-elasticsearch Enable Hyper-V on Windows 10 Install Hyper-V on Windows 10 https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v ElasticSearch on docker - 2nd instance kills the first instance I'm trying to run multiple versions of ElasticSearch at the same time, should be easy. Here are my commands: docker run -d --rm -p 9250:9200 -p 9350:9300 --name es_5_3_3_integration -e "xpack.sec... https://stackoverflow.com/questions/47540547/elasticsearch-on-docker-2nd-instance-kills-the-first-instance ElasticSearch - cannot run two es docker containers at the same time ElasticSearch - cannot run two es docker containers at the same time I'm trying to run 2 services of ElasticSearch using docker-compose.yaml Every time I run docker-compose up -d only one service is https://stackoverflow.com/questions/72273655/elasticsearch-cannot-run-two-es-docker-containers-at-the-same-time Cannot bind to some ports due to permission denied For the last 3 months or so I'm having random errors where I can't bind a specific port where our Identity server is running on my local development workstation. At first I thought it's my broken m... https://stackoverflow.com/questions/48478869/cannot-bind-to-some-ports-due-to-permission-denied [Windows 10] Docker 설치 완벽 가이드(Home 포함) Docker는 경량 가상화 기술인 리눅스 컨테이너 도구입니다. Windows 10 Home과 Pro에서도 몇 가지 설정을 통해 Docker Desktop으로 리눅스 컨테이너를 사용할 수 있습니다. 이 글에서는 Windows 10에서 Docker Desktop을 설치하는 방법을 총 정리합니다. https://www.lainyzine.com/ko/article/a-complete-guide-to-how-to-install-docker-desktop-on-windows-10/ 윈도우10 WSL2 설치하기, WSL2 우분투 설치하기 WSL이란? Linux용 Windows 하위 시스템을 사용하면 개발자가 기존 가상 머신의 오버헤드 또는 듀얼 부팅 설정 없이 대부분의 명령줄 도구, 유틸리티 및 애플리케이션을 비롯한 GNU/Linux 환경을 수정하지 않고 Windows에서 직접 실행할 수 있습니다. WSL2와 WSL1 비교 WSL 2는 Windows 10, 버전 1903, 빌드 18362 이상에서만 사용할 수 있습니다. 윈도우10에서 WSL2 설치해서 우분투 리눅스를 이용해보자 1. 윈 https://gaesae.com/161 Docker 기반의 Elasticsearch 설치 및 실행 본 문서에서는 Docker 환경에서 Elasticsearch 7.9 버전을 설치하고 실행하는 방법에 대해서 설명하고 있습니다. https://jinhokwon.github.io/devops/elasticsearch/elasticsearch-docker/ Korean (nori) Analysis Plugin | Elasticsearch Plugins and Integrations [6.4] | Elastic IMPORTANT: No additional bug fixes or documentation updates will be released for this version. For the latest information, see the current release documentation. Elastic Docs› Elasticsearch Plugins and Integrations [6.4]› Analysis Plugins « kuromoji_numbe https://www.elastic.co/guide/en/elasticsearch/plugins/6.4/analysis-nori.html#analysis-nori-install  
server · Feb. 7, 2023, 9:33 a.m.
elasticsearch docker
Set up minimal security for Elasticsearch
* Please refer to this.  Set up minimal security for Elasticsearch | Elasticsearch Guide [7.16] | Elastic IMPORTANT: No additional bug fixes or documentation updates will be released for this version. For the latest information, see the current release documentation. Elastic Docs› Elasticsearch Guide [7.16]› Secure the Elastic Stack› Configure security for th https://www.elastic.co/guide/en/elasticsearch/reference/7.16/security-minimal-setup.html   * Django setup elasticsearch client with password auth You can pass the elasticsearch URL as from urllib.parse import quote_plus as urlquote elk_base_url = 'elasticsearch://{user_name}:{password}@{host_ip}:{host_port}' elastic_search_url = elk_base_url.format(user_name='my_username', password=urlquote('mysecret_password'), # password may contain special characters host_ip='my-elastic-host-ip', host_port=9200) ELASTICSEARCH_DSL = { 'default': { 'hosts': [elastic_search_url] }, }  
server · Feb. 6, 2023, 5:59 a.m.
elasticsearch
Can I run multiple Elasticsearch instances in one server?
  Yes and I did that recently with my laptop for experimentation with things that I would like to do with ES Cluster. This setup simplifies my environment, instead of using docker or using multiple machines/VMs/EC2 instances. You can download and use the .tar.gz file recommended above, and then you can do one of the following options option 1 - untar the file into two directories: es-01, es-02 then update the config file in each node option 2 - untar the file into one directory: es-instance, copy the config directory to another location with something like path/to/es-01/config, path/to/es-02/config then create a script to launch elasticsearch from the same binary location (which is es-instance) but use different config location (one for es-01/config, one for es-02/config) You need to update the following parameters in config/elasticsearch.yml file to separate one node from the other. cluster.name node.name path.data path.logs http.port   Can I run multiple Elasticsearch instances in one server? Can I run multiple Elasticsearch instances in one server? -If yes, How can I install 2 Elasticsearch instances in a single Linux server. I am aware if we use "yum install" will be installed without any issue. Thanks in Advance https://discuss.elastic.co/t/can-i-run-multiple-elasticsearch-instances-in-one-server/321230 how to run multiple instances of elasticsearch on one host I have several machines each with 128 GB of ram, each host is running a single instance of Elasticsearch. I would like to run another data node on each host and allocate around 30 GB to the jvm he... https://stackoverflow.com/questions/28482449/how-to-run-multiple-instances-of-elasticsearch-on-one-host   You need to prepare two elasticsearch.yml config files to configure settings accordingly and specify these files when startup up the two nodes. /elasticsearch/config/elasticsearch.yml /elasticsearch/config2/elasticsearch.yml /elasticsearch/config2/elasticsearch.yml cluster.name: trinitarian node.name: node-2 path.data: /path/to/data path.logs: path/to/logs network.host: 127.0.0.1 network.bind_host: 127.0.0.1 network.publish_host: 127.0.0.1 http.port: 9500   Linux Assuming your rpm or deb created an init.d script, to start a second node on the same machine do as follows: cd /etc/init.d cp --preserve elasticsearch elasticsearch2 Edit elasticsearch2 script: change # elasticsearch to # elasticsearch2 add node="2" after line prog="elasticsearch" change pidfile=/var/run/elasticsearch/${prog}.pid to pidfile=/var/run/elasticsearch/${prog}${node}.pid change lockfile=/var/lock/subsys/$prog to lockfile=/var/lock/subsys/$prog$node change echo -n $"Starting $prog: " to echo -n $"Starting $prog: (node $node)" change echo -n $"Stopping $prog: " to echo -n $"Stopping $prog: (node $node)" Save the file. Execute chkconfig --add elasticsearch2 service elasticsearch2 start I also had to add -Des.config=<path-to-second-config-files> to get it working   Run multiple elasticsearch nodes as a service on one Ubuntu-Server I have a server running Ubuntu 14.04 with 220 GB of ram on which I'd like to run elasticsearch. According to the documentation, one node should not have more than 32 GB of RAM, so I guess I have to... https://stackoverflow.com/questions/26162690/run-multiple-elasticsearch-nodes-as-a-service-on-one-ubuntu-server   Windows /elasticsearch/bin/elasticsearch-env2.bat if not defined ES_PATH_CONF ( set ES_PATH_CONF=!ES_HOME!\config2 ) /elasticsearch/bin/elasticsearch2.bat CALL "%~dp0elasticsearch-env2.bat" || exit /b 1   Check this: http://localhost:9200/ { "name" : "BEAST", "cluster_name" : "elasticsearch", "cluster_uuid" : "EVBl4ttGSWKP8MJJMivMCg", "version" : { "number" : "7.16.2", "build_flavor" : "default", "build_type" : "zip", "build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb", "build_date" : "2021-12-18T19:42:46.604893745Z", "build_snapshot" : false, "lucene_version" : "8.10.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } http://localhost:9500/ { "name" : "node-2", "cluster_name" : "trinitarian", "cluster_uuid" : "QRUfSRYISH-20jU7x9yxog", "version" : { "number" : "7.16.2", "build_flavor" : "default", "build_type" : "zip", "build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb", "build_date" : "2021-12-18T19:42:46.604893745Z", "build_snapshot" : false, "lucene_version" : "8.10.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }   Rebuild index: PS E:\pythonProjects\trinitarian\test> python manage.py search_index --rebuild --model xxx Are you sure you want to delete the 'board' indexes? [y/N]: y Deleting index 'board' Creating index 'board' Indexing 26 'Board' objects PS E:\pythonProjects\trinitarian\test>   Test with this code (test.py): import elasticsearch elastic = elasticsearch.Elasticsearch(hosts=["localhost:9200"]) indices = elastic.indices.get_alias().keys() print(indices) elastic2 = elasticsearch.Elasticsearch(hosts=["localhost:9500"]) indices2 = elastic2.indices.get_alias().keys() print(indices2)   Result: E:\pythonProjects\trinitarian\venv\Scripts\python.exe E:/pythonProjects/trinitarian/test/app/test.py dict_keys(['a', 'b', 'c', 'board']) dict_keys(['board']) Process finished with exit code 0  
server · Feb. 6, 2023, 4:18 a.m.
elasticsearch
Jsoup - Working with URLs
Following example will showcase methods which can provide relative as well as absolute URLs present in the html page. Syntax String url = "http://www.tutorialspoint.com/"; Document document = Jsoup.connect(url).get(); Element link = document.select("a").first(); System.out.println("Relative Link: " + link.attr("href")); System.out.println("Absolute Link: " + link.attr("abs:href")); System.out.println("Absolute Link: " + link.absUrl("href")); Where document − document object represents the HTML DOM. Jsoup − main class to connect to a url and get the html content. link − Element object represent the html node element representing anchor tag. link.attr("href") − provides the value of href present in anchor tag. It may be relative or absolute. link.attr("abs:href") − provides the absolute url after resolving against the document's base URI. link.absUrl("href") − provides the absolute url after resolving against the document's base URI. Description Element object represent a dom elment and provides methods to get relative as well as absolute URLs present in the html page. Example 1. sample html <html> <head> <title></title> <script type="text/javascript" src="/resource/js/jquery-1.7.1.min.js"></script> <link type="text/css" href="/resource/css/admin/general.css" rel="stylesheet" /> </head> <body> <span id="navi"> <img src="https://www.phenomena.com/media/xstorage/banner/2022-03-17_PM1109_L46DRH2Y8P.png" alt="" /> </span> </body> </html> 2. code package com.bad.blood.test; import java.io.IOException; import java.net.URL; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class Test { public static void main(final String[] args) throws IOException{ Document doc = Jsoup.parse( new URL("http://127.0.0.1:8080/index.html").openConnection().getInputStream(), "UTF-8", "http://127.0.0.1:8080/"); Elements elems = doc.select("[src]"); for( Element elem : elems ){ if( !elem.attr("src").equals(elem.attr("abs:src")) ){ elem.attr("src", elem.attr("abs:src")); } } elems = doc.select("[href]"); for( Element elem : elems ){ if( !elem.attr("href").equals(elem.attr("abs:href")) ){ elem.attr("href", elem.attr("abs:href")); } } System.out.println(doc.toString()); } } 3. result html <html> <head> <title></title> <script type="text/javascript" src="http://127.0.0.1:8080/resource/js/jquery-1.7.1.min.js"></script> <link type="text/css" href="http://127.0.0.1:8080/resource/css/admin/general.css" rel="stylesheet" /> </head> <body> <span id="navi"> <img src="https://www.phenomena.com/media/xstorage/banner/2022-03-17_PM1109_L46DRH2Y8P.png" alt="" /></span> </body> </html>   jsoup: Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety jsoup News Bugs Discussion Download API Reference Cookbook Try jsoup jsoup » jsoup: Java HTML Parser jsoup: Java HTML Parser jsoup is a Java library for working with real-world HTML. It provides a very convenient API for fetching URLs and extracting and m https://jsoup.org/  
java · Feb. 3, 2023, 7:10 a.m.
jsoup
Changing Tomcat's Default Session ID (JSESSIONID)
You can pass it as a parameter when starting the server. -Dorg.apache.catalina.SESSION_COOKIE_NAME=MYJSESSIONID -Dorg.apache.catalina.SESSION_PARAMETER_NAME=myjsessionid   * Eclipse Double click server - Open launch configuration  
server · Feb. 3, 2023, 6:47 a.m.
tomcat
Java's DecimalFormat method rounds up by force. How do we prevent that?
In https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html Customizing Formats (The Java™ Tutorials > Internationalization > Formatting) A browser with JavaScript enabled is required for this page to operate properly. Documentation The Java™ Tutorials Hide TOC Formatting Numbers and Currencies Using Predefined Formats Customizing Formats Dates and Times Using Predefined Formats Customizing https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html value: 123456.789 pattern: ###.## output: 123456.79 The value has three digits to the right of the decimal point, but the pattern has only two. The format method handles this by rounding up.   We can prevent that like this. package com.bad.blood.test; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.NumberFormat; public class Test { public static void main(String args[]) { double irr = 9.7485232; DecimalFormat df = new DecimalFormat("###.00"); String str = df.format(irr); System.out.println(str); // 9.75 // method 1 String str2 = String.valueOf(irr); System.out.println(str2.substring(0, str2.indexOf('.') + 3)); // 9.74 // method 2 System.out.println( (double)(int)(irr * 100) / 100 ); // 9.74 // method 3 NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setRoundingMode(RoundingMode.DOWN); nf.setGroupingUsed(true); System.out.println(nf.format(irr)); // 9.74 } } output: 9.75 9.74 9.74 9.74  
java · Feb. 3, 2023, 6:35 a.m.
Type conversion in Java
Converting int to string String myString = Integer.toString(my int value) or  String str = "" + i   Converting String to int int i = Integer.parseInt(str); or  int i = Integer.valueOf(str).intValue();   Double to String : String str = Double.toString(i);   Long to String : String str = Long.toString(l);   Float to String : String str = Float.toString(f);   String to double : double d = Double.valueOf(str).doubleValue();   String to long : long l = Long.valueOf(str).longValue(); or long l = Long.parseLong(str);   String to float : float f = Float.valueOf(str).floatValue(); Decimal to binary : int i = 42; String binstr = Integer.toBinaryString(i); Decimal to hexadecimal : int i = 42; String hexstr = Integer.toString(i, 16); or String hexstr = Integer.toHexString(i); or (with leading zeroes and uppercase) public class Hex {      public static void main(String args[]){        int i = 42;        System.out.print        (Integer.toHexString( 0x10000 | i).substring(1).toUpperCase());       } }   Hexadecimal (String) to integer : int i = Integer.valueOf("B8DA3", 16).intValue(); or int i = Integer.parseInt("B8DA3", 16);     ASCII code to String int asciiVal = 87; String str = new Character((char) asciiVal).toString();   Float to integer (Round off the decimal place) float a = 1.1f; float b = 2.1f; int i = ((int)(100-a/b*100)); System.out.println(i); // 47  
java · Feb. 3, 2023, 5:55 a.m.
Remove Trailing Slash in NGINX
Sometimes NGINX may show trailing slash in website URLs. Here’s how to remove trailing slash in NGINX to make your URLs look more intuitive.   Remove trailing slash in NGINX Here are the steps to remove trailing slash in NGINX.   1. Open NGINX configuration file Open terminal and run the following command to open NGINX server configuration file. $ sudo vi /etc/nginx/nginx.conf If you have configured separate virtual hosts for your website (e.g www.example.com), such as /etc/nginx/sites-enabled/website.conf then open its configuration with the following command $ sudo vi /etc/nginx/sites-enabled/website.conf 2. Remove trailing slash Add the following rewrite rule in server block as shown in bold. Replace example.com below with your domain name server { listen 80; server_name example.com; rewrite ^/(.*)/$ /$1 permanent; } In the above code, the rewrite statement will redirect all URLs to those without trailing slash. If you want to remove trailing slash from only a specific URL (e.g /product/) then update the rewrite statement as shown below. server { listen 80; server_name mydomain.com; rewrite ^/product/$ /product permanent; }   * You can also use this method. Remove the trailing slash from all paths except mypath. location ~ ^/mypath(.*) { try_files $uri @tomcat; } location ~ (?<no_slash>.*)/$ { return 301 $no_slash; } ... location / { try_files $uri @tomcat; } location @tomcat { ... }   3. Restart NGINX Server Run the following command to check syntax of your updated config file. $ sudo nginx -t If there are no errors, run the following command to restart NGINX server. $ sudo service nginx reload #debian/ubuntu $ systemctl restart nginx #redhat/centos  
server · Jan. 29, 2023, 9:54 p.m.
nginx
How does one display progress of a file copy operation in Java. without using Swing e.g. in a Web app?
Here is how to copy a file in java and monitor progress on the commandline: package com.bad.blood.test; import java.io.*; import org.springframework.util.ResourceUtils; public class FileCopyProgress { public static void main(String[] args) throws FileNotFoundException { System.out.println("copying file"); File filein = ResourceUtils.getFile("classpath:static/images/5941188.png"); File fileout = new File("src/main/resources/static/images/5941188_copy.png"); FileInputStream fin = null; FileOutputStream fout = null; long length = filein.length(); long counter = 0; int r = 0; byte[] b = new byte[1024]; try { fin = new FileInputStream(filein); fout = new FileOutputStream(fileout); while( (r = fin.read(b)) != -1) { counter += r; System.out.println( 1.0 * counter / length ); fout.write(b, 0, r); } } catch(Exception e){ System.out.println("foo"); } } } Result: copying file 0.0012724448586517551 0.0025448897173035103 0.0038173345759552656 0.0050897794346070205 0.006362224293258776 ... 0.9950518794656725 0.9963243243243243 0.9975967691829761 0.9988692140416279 1.0 ref. https://www.baeldung.com/java-copy-file https://stackoverflow.com/questions/44399422/read-file-from-resources-folder-in-spring-boot https://stackoverflow.com/questions/11182114/how-does-one-display-progress-of-a-file-copy-operation-in-java-without-using-sw
java · Jan. 16, 2023, 9:01 p.m.
Encoding URL query parameters in Java
Q: How does one encode query parameters to go on a url in Java? A: java.net.URLEncoder.encode(String s, String encoding) can help too. It follows the HTML form encoding application/x-www-form-urlencoded. URLEncoder.encode(query, "UTF-8"); On the other hand, Percent-encoding (also known as URL encoding) encodes space with %20. Colon is a reserved character, so : will still remain a colon, after encoding. ref. https://stackoverflow.com/questions/5330104/encoding-url-query-parameters-in-java
java · Jan. 16, 2023, 8:34 p.m.
urlencode
  • 1
  • 2
  • 3 (current)
  • 4
  • 5