Postingan

Fix the header of a DataTable,

To fix the header of a DataTable, you can use the fixedHeader extension provided by DataTables. This extension will fix the header of the table in place while allowing the rest of the table to scroll. Here's how you can use it: 1. First, include the datatables.fixedHeader.min.js file in your HTML document. You can download this file from the DataTables website or use a CDN link. <script src="https://cdn.datatables.net/fixedheader/3.1.9/js/dataTables.fixedHeader.min.js"/></script/> 2. Then, initialize your DataTable with the fixedHeader option set to true. $(document).ready(function() { $('#example').DataTable({ fixedHeader: true }); }); This will fix the header of your table in place while allowing the rest of the table to scroll. You can also customize the behavior of the fixed header by passing in additional options to the fixedHeader option. For example, you can change the offset of the header from the top of the viewp

Add a row to a DataTable using jQuery

To add a row to a DataTable using jQuery, you can use the row.add() method. Here's an example: var table = $('#myTable').DataTable(); var data = ['John', 'Doe', 'johndoe@example.com']; table.row.add(data).draw(); In this example, myTable is the ID of the DataTable, data is an array containing the data for the new row, and draw() is called to redraw the table with the new row added. You can also add a row using an object instead of an array. Here's an example: var table = $('#myTable').DataTable(); var data = { first_name: 'John', last_name: 'Doe', email: 'johndoe@example.com' }; table.row.add(data).draw(); In this example, data is an object containing the data for the new row, and the keys correspond to the column names in the table.

Convert JSON data to input text on a datatable using jQuery

To convert JSON data to input text on a datatable using jQuery, you can use the render option of the columns configuration to specify a function that returns the HTML markup for the input text. Here's an example: // Assuming JSON data in the format [{ "name": "John", "age": 30 }, ...] $(document).ready(function() { $('#myTable').DataTable({ data: myData, // myData is the JSON data columns: [ { data: 'name', title: 'Name' }, { data: 'age', title: 'Age' }, { data: null, title: 'Input', render: function(data, type, row, meta) { return '<input type="text" value="' + data.name + '" />'; } } ] }); }); In this example, the data parameter of the render function is the object containing the data for the current row. We extract the name property from this object and use it as the initia

Check if an IP address is active or not with PHP

To check if an IP address is active or not with PHP, you can use various approaches. Here are a few examples: 1. Using ping command with exec() function: $ip = '192.168.1.1'; if (exec(sprintf("ping -c 1 -W 2 %s", escapeshellarg($ip))) == true) { echo "IP is active"; } else { echo "IP is not active"; } This code sends a single ping request with a timeout of 2 seconds. If the IP address responds, the exec() function will return a non-empty result, and the code will output "IP is active". Otherwise, it will output "IP is not active". 2. Using fsockopen() function to check if a port is open: $ip = '192.168.1.1'; $port = 80; if($fp = fsockopen($ip,$port,$errCode,$errStr,1)){ echo "IP is active"; fclose($fp); } else { echo "IP is not active"; } This code checks if port 80 is open on the IP address using the fsockopen() function. If the connection is successful, the code w

Send image URL using whatsapp-web.js

To send an image with a URL using whatsapp-web.js, you can use the Client.sendImage method with the url parameter. Here is an example code: const fs = require('fs'); const path = require('path'); const axios = require('axios'); const qrcode = require('qrcode-terminal'); const { Client , MessageMedia } = require('whatsapp-web.js'); const client = new Client(); const folderPath = 'D:/xampp/htdocs/api-whatsapp/downloads'; function sendFileFromUrl(chatId, message, fileUrl) { const filename = path.basename(fileUrl); const filePath = path.join(folderPath, filename); axios({ url: fileUrl, responseType: 'stream' }).then(response => { response.data.pipe(fs.createWriteStream(filePath)); response.data.on('error', err => { console.error(err); }); response.data.on('end', () => { console.log('File downloaded successfully!'); const

Replication MySQL 5.7 Ubuntu 20.04

SERVER MASTER 192.168.2.10 mysql user : root mysql password : password_master$ mysql user : user_replikasi$ mysql password : password_replikasi$ SERVER SLAVE 192.168.2.20 mysql user : root mysql password : password_replikasi$ Setting on server master 1. Update Ubuntu sudo apt update sudo apt list --upgradable sudo apt upgrade sudo reboot 2. Create a Sudo User on Ubuntu adduser example_user adduser example_user sudo su - example_user 3. Install MySQL wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb sudo dpkg -i mysql-apt-config_0.8.12-1_all.de sudo apt update sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 sudo apt update sudo apt-cache policy mysql-server sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7* sudo mysql_secure_installation mysql -u root -p SELECT VERSION(); 4. Masuk ke file sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf: bind-address = 192.168.2.10 server-id

Download a file on Node.js

To download a file on Node.js, you can use the built-in fs module and the https or http module to make a request to the server and save the response to a file. Here's an example of how you can download a file using https module: const https = require('https'); const fs = require('fs'); const fileUrl = 'https://example.com/file.pdf'; const filePath = './downloads/file.pdf'; const file = fs.createWriteStream(filePath); https.get(fileUrl, (response) => { response.pipe(file); file.on('finish', () => { file.close(); console.log('File downloaded successfully.'); }); }).on('error', (err) => { fs.unlink(filePath, () => { console.error(`Error downloading file: ${err}`); }); }); In the above example, we first define the URL of the file we want to download and the path where we want to save the file. We then create a write stream to the file using the fs module. Next, we make a https.get() re

Check the status of a WhatsApp account using whatsapp-web.js

To check if a phone is registered on WhatsApp, you will need to create a WhatsApp Web session using the whatsapp-web.js library. Once you have created a session, you can use the isRegisteredUser method of the WWebJS object to check if the phone number is registered on WhatsApp. Here is an example code snippet that demonstrates how to check if a phone number is registered on WhatsApp using the whatsapp-web.js library: const { Client } = require('whatsapp-web.js'); const qrcode = require('qrcode-terminal'); const client = new Client(); client.on('qr', (qr) => { qrcode.generate(qr, {small: true}); }); client.on('ready', () => { console.log('Client is ready!'); // Check if phone number is registered on WhatsApp const phoneNumber = '62123456789'; // Replace with phone number to check client.isRegisteredUser(phoneNumber + '@c.us').then((isRegistered) => { if (isRegistered) { cons

Install FTP server on VPS

To install and configure an FTP server on your VPS digital ocean, you can follow these steps: 1. Log in to your VPS using SSH. 2. Update the package list by running the following command: sudo apt-get update 3. Install the FTP server package, vsftpd: sudo apt-get install vsftpd 4. Once the installation is complete, you need to configure the FTP server. Open the configuration file for vsftpd: sudo nano /etc/vsftpd.conf 5. Make the following changes to the configuration file: anonymous_enable=NO local_enable=YES write_enable=YES chroot_local_user=YES user_sub_token=$USER local_root=/home/$USER/ftp pasv_min_port=40000 pasv_max_port=50000 listen_ipv6=YES Here, you are disabling anonymous login, enabling local users, allowing write access, setting the local root directory to the user's home directory plus an ftp directory, and enabling passive mode. 6. Save the configuration file and exit. 7. Restart the vsftpd service to apply the changes: sudo systemctl

Add the ability to select rows in a jQuery DataTable

To add the ability to select rows in a jQuery DataTable, you can use the select option provided by the DataTables library. Here's an example of how to add row selection to a DataTable: $('#myTable').DataTable({ select: true }); This will enable row selection for the table with the ID myTable. Once you've added row selection, you can access the selected rows using the rows({selected:true}) method: var selectedRows = $('#myTable').DataTable().rows({selected:true}).data(); This will return an array of data objects for the selected rows. You can also handle the select event to perform custom actions when a row is selected: $('#myTable').on('select.dt', function(e, dt, type, indexes) { var selectedRows = dt.rows({selected:true}).data(); // do something with the selected rows });