React useEffect

  • ## useEffect Hook replaces the componentDidMount, componentDidUpdate, and componentWillUnmount lifecycle methods.
– deal with side effects like data fetching and state or variable changes for React functional components. It takes 2 arguments:
1. function
2. dependency array: run every time if value is updated.
  • Runs Once on First Render
useEffect(() => {
console.log(‘This runs once on first render’);
}, []);
  • Runs On a Specified Dependency
useEffect(() => {
console.log(“Count variable has changed!”)
}, [count]);
  • for multiple variable changes?
useEffect(() => {
console.log(“Some count variable has changed!”)
}, [count, count1, count2]);
  • useEffect with Cleanup
run right before the component unmounts, just like componentWillUnmount,
simply use its return function like so:
useEffect(() => {
console.log(‘This hook is running.’);
return () => {
console.log(‘This hook is now unmounting.’);
};
});

React useCallback and useMemo

  • React’s useCallback Hook can be used to optimize the rendering behavior of your React function components
  • Note: Don’t mistake React’s useCallback Hook with React’s useMemo Hook. While useCallback is used to memoize functions, useMemo is used to memoize values.
  • useCallback is used to memoize functions, React memo is used to wrap React components to prevent re-renderings.

! example here Code

Cannot enter phpmyadmin as root (MySQL 5.7)

MySQL 5.7 changed the secure model: now MySQL root login requires a sudo (while the password still can be blank).
I.e., phpMyAdmin will be not able to use root credentials.
The simplest (and safest) solution will be create a new user and grant required privileges.
1. Connect to mysql
sudo mysql –user=root mysql

2. Create a user for phpMyAdmin
Run the following commands (replacing some_pass by the desired password):
CREATE USER ‘phpmyadmin’@’localhost’ IDENTIFIED BY ‘some_pass’;GRANT ALL PRIVILEGES ON *.* TO ‘phpmyadmin’@’localhost’ WITH GRANT OPTION;FLUSH PRIVILEGES;If your phpMyAdmin is connecting to localhost, this should be enough.

3. Optional: allow remote connections
Remember: allow a remote user to have all privileges is a security concern.
With this in mind, if you want this user to have the same privileges during remote connections, additionally run (replacing some_pass by the password used in Step #2):
CREATE USER ‘phpmyadmin’@’%’ IDENTIFIED BY ‘some_pass’;GRANT ALL PRIVILEGES ON *.* TO ‘phpmyadmin’@’%’ WITH GRANT OPTION;FLUSH PRIVILEGES;

Directory Functions for php

list of directory function


 

  1. chdir — Change directory
  2. chroot — Change the root directory
  3. closedir — Close directory handle
  4. dir — Return an instance of the Directory class
  5. getcwd — Gets the current working directory
  6. opendir — Open directory handle
  7. readdir — Read entry from directory handle
  8. rewinddir — Rewind directory handle
  9. scandir — List files and directories inside the specified path

MIME Types

MIME Types

MIME types tell browsers how to handle specific extensions. For example, the text/html MIME type equates to .htm, .html, and .shtml extensions on most servers, and this tells your browser to interpret all files with those extensions as HTML files. You can alter or add new MIME types specifically for your site (note that you can not alter the system defined MIME type values). MIME types are often used to handle new technologies as they appear. When WAP technology first appeared no one had these extensions set up on their server. With MIME types, however, you could have set it up yourself and begun serving WAP pages immediately.

example

text/richtext rtx
text/plain txt text conf def list log in

Apache Handlers

Apache Handlers

Apache handlers control how the Apache web server software manages certain file types and extensions for your site. Apache comes configured to handle CGI scripts and server-parsed files. You can configure Apache to handle a new file type with an existing handler by manually adding the handler and extension below. For example, to have the server treat files with the extension .example as CGI files, you would type “cgi-script” under Handler and “.example” under Extension(s).

Cron Email

Cron Email

Send an email every time a cron job runs. less »

You can have cron send an email everytime it runs a command. If you do not want an email to be sent for an individual cron job you can redirect the command’s output to /dev/null like this: mycommand >/dev/null 2>&1