Skip to content

Instantly share code, notes, and snippets.

function sort_by_value($a, $b) {
return $b['score'] > $a['score'] ? 1 : -1;
}
//sort using usort
usort($events_temp, 'sort_by_value');
----------Edit cron job ---------------------
-> write comman "crontab -e"
-> press "i"
-> go to last cron job.
-> add new cron job
-> press ESC -> press ":wq"
----------- File Permission give ------------
*Give permission to .sh file*
*********
Open file path
--------------------
$myfile = fopen("data/finalized-ids.txt", "a+") or die("Unable to open file!");
Write something into file
--------------
fwrite($myfile, "event_ids,". PHP_EOL);
Clone tables
---------------
CREATE TABLE app_cities_temp LIKE app_cities;
INSERT INTO app_cities_temp SELECT * FROM app_cities;
1 --> create local server using pythin
run this commnad -> python -m SimpleHTTPServer
2 --> then open your server's ip address in browser.
Boom. your server is showing all file using only IP address. Warning - do ctrl + c after work is done. other wise your file publiclly shows on this ip.
// Reset auto increment id
ALTER TABLE tablename AUTO_INCREMENT = 1
// copy new table with indexes (Do not copy data)
CREATE TABLE newtable LIKE oldtable;
@Bhavya8181
Bhavya8181 / PHP File Open - Read - Close
Created February 12, 2024 05:53 — forked from jack2jm/PHP File Open - Read - Close
how to open, read, and close a file on the server.
Modes Description
r -> Open a file for read only. File pointer starts at the beginning of the file
w -> Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file
a -> Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist
x -> Creates a new file for write only. Returns FALSE and an error if file already exists
r+ -> Open a file for read/write. File pointer starts at the beginning of the file
w+ -> Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file
a+ -> Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist
x+ -> Creates a new file for read/write. Returns FALSE and an error if file already exists
Here is my learning from laravel things.
1. Homepage -> Route.php -> Controller -> Fetch Neccessory Information Database -> Eloquont Model -> Get Reposne -> COntroller -> Show Data.
// reload page when events actual starts
try{
if($diff_seconds_event_starts && $diff_seconds_event_starts> 0){
$current_page_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";;
header("Refresh: $diff_seconds_event_starts; url=$current_page_url");
}
}catch(Exception $e){}
$ct_daily_time = date('H:i:s');
$is_user_entry_enabled = false;
if (strtotime($ct_daily_time) > strtotime('08:25:00') && strtotime($ct_daily_time) < strtotime('17:15:00')) {
$is_user_entry_enabled = true;
}
if (!$is_user_entry_enabled) {
return response()->json([
'status' => false,
'message' => 'Entry Restricted for this Session, Please Login as Per your Scheduled Date & Time (8.30 AM to 5.00 PM)',