Postingan

Generate an input form in a jQuery datatable

To generate an input form in a jQuery datatable, you can use the render function of a column definition to return an HTML string that contains the input element. Here's an example: HTML: <div class="col-md-12"> <button type="button" class="btn btn-sm btn-primary" id="mct_btn_tambah"><span class="fa fa-plus"></span> Tambah Tindakan</button> <table id="mct_table" class="table" style="width:100%;"></table> </div> JAVASCRIPT: <script type="text/javascript"> var mct = function () { this.table = ''; var self = this; this.init = function () { self.table = $('#mct_table').DataTable({ info: false, paging:false, sorting:false, searching:false, orderCellsTop: true, columns: [ {data: null, title:'No.', name: 'no', width: '2

Check if the FTP service is running on an Ubuntu server with PHP

You can use the exec() function in PHP to execute a shell command to check the status of the FTP service on a remote server. Here's an example code that uses the systemctl command to check if the FTP service is running on an Ubuntu server: $server = '192.168.1.100'; // Replace with your server IP $username = 'username'; // Replace with your server username $password = 'password'; // Replace with your server password // SSH connection $connection = ssh2_connect($server, 22); ssh2_auth_password($connection, $username, $password); // Execute systemctl command to check FTP service status $stream = ssh2_exec($connection, 'systemctl status vsftpd.service'); stream_set_blocking($stream, true); // Get command output $output = stream_get_contents($stream); // Check if FTP service is active if (strpos($output, 'Active: active (running)') !== false) { echo 'FTP service is running.'; } else { echo 'FTP service is not running.&

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