Posts
Getting Started With React Native
To develop apps with React Native, instead NodeJS and npm. Expo is very particular about the build version, so you can have multiple versions of NodeJS installed using nvm like this:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash nvm install 16.15.0 nvm use 16.15.0 #nvm use system #to go back to the default system NodeJS Install the expo cli with the command:
npm install -g expo-cli Then, using expo create and run a new project
Posts
Send File Across Network
On Linux, there’s almost always more than one way to do anything. Sending a file across from one Linux server to no different.
NetCat First, with NetCat. The receiver is the TCP listener.
On the receiving end:
nc -l 9000 > newfile.txt On the sending end:
cat myfile.txt | nc -w 2 myserver 9000 Python web server Python has a built-in HTTP server module that can be used to host files, and curl or wget can be used to download files.
Posts
Using Elasticsearch Java Sdk
Starting with an empty Gradle project, the dependencies for the ElasticSearch Java SDK were added to the build.gradle file:
//build.gradle dependencies { implementation 'co.elastic.clients:elasticsearch-java:8.1.3' implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3' implementation 'jakarta.json:jakarta.json-api:2.0.1' } Then, a record type for storing data is defined:
record Book(String title, String author, int publishedYear) { } Get a reference to the ElasticSearch client object, which will be used for making any requests:
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build(); ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); ElasticsearchClient client = new ElasticsearchClient(transport); Create the index if it does not already exist (use dynamic mappings for now).
Posts
Nginx Load Balancer
For this blog post, nginx has been installed on 3 servers: webserver1, webserver2, and loadbalancer.
To configure an nginx server as a load balancer, edit the /etc/nginx/sites-enabled/default file, and configure an upstream servers block as follows:
upstream webserverz { server webserver1; server webserver2; } Then, configure the nginx server in the same configuration file to act as a reverse proxy server by editing the “location /” block to the following, with the upstream block’s name:
Posts
Documentdb Change Streams
AWS DocumentDB is a MongoDB 4.0 compatible offering from AWS. It implements Change Streams for capturing changes from the database. Change Streams are available on both the DocumentDB 3.6 and 4.0 engines.
To connect to DocumentDB, we would have to create an EC2 instance to run the MongoDB shell, so I started a Ubuntu 20.04 VM. For installing the legacy shell, the steps to perform are:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - echo "deb [ arch=amd64,arm64 ] http://repo.
Posts
Spring Data JPA
The Repository pattern is commonly used in Java Spring applications. It abstracts the story and retrieval of data from a data store. The repository is typically called from a Service class. For a web application, the Service class is called from the Controller class.
First, we define the entity class with the fields that we have to store:
package com.pockettheories; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class CarEntity { @Id @GeneratedValue(strategy = GenerationType.
Posts
Getting Started With Apacheds
RedHat Enterprise Linux 8 does not include the OpenLDAP server package. To install ApacheDS instead:
sudo yum install -y java-1.8.0-openjdk curl -OL https://dlcdn.apache.org//directory/apacheds/dist/2.0.0.AM26/apacheds-2.0.0.AM26-x86_64.rpm sudo rpm -i apacheds-2.0.0.AM26-x86_64.rpm sudo vi /opt/apacheds-2.0.0.AM26/conf/wrapper.conf #Put Java path sudo /etc/init.d/apacheds-2.0.0.AM26-default start Then, install the LDAP client utility to connect to the server:
sudo yum install -y openldap-clients sudo yum install -y vim-enhanced ldapsearch -h $(hostname -f):10389 -D 'uid=admin,ou=system' -w 'secret' -b '' -s base The server contains the example.
Posts
Spring Boot Cli Hello World
Java has never had the easiest of Hello World programs. For the very simplest Hello World, we would have to create a class, define a static method within that class, and to display output, there’s a call to “System.out.println”:
public class MyMain { public static void main(String args[]) { System.out.println("Hello World"); } } That’s without the use of packages (namespaces), Maven, or the Spring framework.
Place the .java file in src/main/java and creating a pom.
Posts
Selinux Config for Apache
This is a go at configuring SE Linux for the Apache web server.
To install Apache on a RedHat Enterprise Linux 8 server and to change the default port:
sudo dnf install -y httpd sudo sed -i 's/Listen 80/Listen 1100/' /etc/httpd/conf/httpd.conf sudo systemctl restart httpd Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. -- Unit httpd.service has begun starting up.
Posts
Serving Tmp Files From Nginx
Daemons storing files in /tmp makes implementing security harder, especially when they run with root privileges - daemons should be storing runtime data into /run instead and persistent data in /var/lib (plus there’s /var/run/___ and /var/cache/___ for… stuff).
When installing nginx on RedHat Enterprise Linux 8.0, nginx will not serve files from the /tmp directory because of PrivateTmp in the SystemD unit file. For some reason, if you have to serve files from /tmp, PrivateTmp has to be disabled: