Skip to content

Commit

Permalink
new files added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhu007 committed Mar 21, 2022
1 parent 75e485b commit fc6fc41
Show file tree
Hide file tree
Showing 14 changed files with 1,283 additions and 113 deletions.
58 changes: 58 additions & 0 deletions php_scripts/codesponsors_snippets/check_work_day_type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
# Getting Work day Type
# Suppose I consider the date with time 2018-12-25 19:28:00
# You need to find out this date&time among the list of Business day, Non-business day, Weekends, And Holidays
# Holidays list & Week days are in Array
# Consider Business works 9:00 AM to 6:00PM

$holidays = ['01-01-2018','26-12-2018','10-07-2019','15-08-2019'];
$weekdays = [0,1,2,3,4,5,6]; //['mon','tue','wed','thu','fri']
$input_date = '2018-12-25 19:28:00'; //'YYYY-MM-DD h:i:s'
$business_start_time = "19:00";
$business_end_time = "20:00";
$type = "";

#1st check Holiday or not
$dt = new DateTime($input_date);
$date = $dt->format('d-m-Y');
if(in_array($date,$holidays))
{
$type = "Holiday";
}


#2nd Check week end or not
$wk_no = date("w", strtotime($input_date)); //["0"=>"sun","1"=>"mon"....."6"=>"sat"]
if(($wk_no == 0 || $wk_no == 6) && $type != "Holiday" && !in_array($wk_no,$weekdays))
{
$type = "Weekend";
}

#3rd Check work day even weekend also working day or not
if(in_array($wk_no,$weekdays) && $type != "Weekend" && $type != "Holiday")
{
$type = "Working day";
}

#4th Condition check Business hour or non-business hour
$begin = date("H:i", strtotime($business_start_time)); // gives 24 format
$end = date("H:i", strtotime($business_end_time));
$now = date("H:i", strtotime($input_date));
if (($now >= $begin && $now <= $end) && $type == "Working day")
{
$type = "business hour";
}
else if($type == "Weekend")
{
$type = "Weekend";
}
else if($type == "Holiday")
{
$type = "Holiday";
}
else
{
$type = "Non-business hour";
}

echo $type."<br/>";
99 changes: 99 additions & 0 deletions php_scripts/codesponsors_snippets/fetch_api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<head></head>
<body>
<script>
// if (!('fetch' in window)) {
// console.log('Fetch API not found, try including the polyfill');
// return false;
// }
// fetch("https://swapi.co/api/people/1/").then(function(response){
// console.log("Status:",response.status);

// response.json().then(function(data){
// console.log("Fetch Result:",data);
// }).catch(function(err){
// console.log("Fetch Error", err);
// });

// });

// https://javascript.info/promise-basics

function checkStatus(response){
if(response.status === 200){
return Promise.resolve(response);
}else{
return Promise.reject(
new Error(response.statusText));
}

}

function getJSON(response){
return response.json();
}


fetch("https://swapi.co/api/people/1/")
.then(checkStatus)
.then(getJSON)
.then(function(response){
console.log("Status:",response.status);
// response.json().then(function(data){
// console.log("Fetch Result:",data);
// }).catch(function(err){
// console.log("Fetch Error", err);
// });
});

// Fetch options
// Method
// HTTP Headers
// body
// credentials
// cors

// example of options
// var options = {
// "method": "post",
// "headers":{
// "Authorization":"Bearer XXXX"},
// "body":"Hello body!"
// };

// fetch mode options
// same-origin
// cors
// cors-with-forced-preflight
// no-cors

// <!-- Now do some sample code for post -->
// var name = "siddhu";
// var body = "some text";
// var url = "https://jsonplaceholder.typicode.com/posts";
// fetch(url,{
// method:'POST',
// headers:{
// 'Accept':'application/json, text/plain, */*',
// 'Content-type':'application/json'
// },
// body:JSON.stringify({name:name,body:body})
// }).then(checkStatus)
// .then(getJSON)
// .then(function(response){
// console.log("Status:",response.status);

// response.json().then(function(data){
// console.log("Fetch Result:",data);
// }).catch(function(err){
// console.log("Fetch Error", err);
// });
// });


</script>
</body>
</html>
40 changes: 40 additions & 0 deletions php_scripts/codesponsors_snippets/file_upload_imgur.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<body>

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files" id="_testFile">
<input type="submit" name="submit" id="">
</form>
<pre></pre>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("form").submit(function(e){
alert();
event.preventDefault();
var form = new FormData();
form.append("image", $('input[type=file]')[0].files[0]);
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.imgur.com/3/image",
"method": "POST",
"headers": {
"Authorization": "Client-ID 6f383a05a8eab0f"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(settings).done(function (response) {
console.log(response);
$("pre").text(response);
});
});
</script>
</body>
</html>
169 changes: 169 additions & 0 deletions php_scripts/codesponsors_snippets/google_map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAXkP7Z7L54odTOQJshVFVvQSt-FkAd77I&sensor=false&libraries=places"></script> <script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
console.log(place);
/* console.log(place);
console.log(place.address_components[0]['types'][0]); */
var address = place.formatted_address;
document.getElementById("formatted_address").value = address;
var name = place.name;
document.getElementById("name").value = name;
var url = place.url;
document.getElementById("url").value = url;
var latitude = place.geometry.location.lat();
document.getElementById("latitude").value = latitude;
var longitude = place.geometry.location.lng();
document.getElementById("longitude").value = longitude;
var website = place.website;
document.getElementById("website").value = website;
var place_id = place.place_id;
document.getElementById("Place_id").value = place_id;
$( place.address_components ).each(function( index, value ) {
// console.log( index, value );
$( value.types ).each(function( key, mainvalue ) {
//console.log( key, mainvalue );
if(mainvalue === 'locality')
{
//console.log( "siddhu", value.long_name );
document.getElementById("client_location").value = value.long_name;
}
if(mainvalue === 'postal_code')
{
//console.log( "siddhu", value.long_name );
document.getElementById("postal_code").value = value.long_name;
}
if(mainvalue === 'administrative_area_level_1')
{
//console.log( "siddhu", value.long_name );
document.getElementById("state").value = value.long_name;
}
if(mainvalue === 'country')
{
//console.log( "siddhu", value.long_name );
document.getElementById("country").value = value.long_name;
}
});
});
});
});
</script>
<div class="container">
<h2>Google Location autocomplete made by Siddhu</h2>
<form>
<div class="form-group">
<label for="email">Location:</label>
<input type="text" class="form-control" id="txtPlaces" placeholder="Enter a location" name="map" autocomplete="off" />
</div>
<div class="form-group">
<label for="formatted_address">formatted_address:</label>
<input type="text" class="form-control" id="formatted_address" >
</div>
<div class="form-group">
<label for="formatted_address">name:</label>
<input type="text" class="form-control" id="name" >
</div>
<div class="form-group">
<label for="formatted_address">url:</label>
<input type="text" class="form-control" id="url" >
</div>
<div class="form-group">
<label for="formatted_address">latitude:</label>
<input type="text" class="form-control" id="latitude" >
</div>
<div class="form-group">
<label for="formatted_address">longitude:</label>
<input type="text" class="form-control" id="longitude" >
</div>
<div class="form-group">
<label for="formatted_address">website:</label>
<input type="text" class="form-control" id="website" >
</div>
<div class="form-group">
<label for="formatted_address">city:</label>
<input type="text" class="form-control" id="client_location" name="city" >
</div>
<div class="form-group">
<label for="formatted_address">state:</label>
<input type="text" class="form-control" id="state" name="state" >
</div>
<div class="form-group">
<label for="formatted_address">country:</label>
<input type="text" class="form-control" id="country" name="country" >
</div>
<div class="form-group">
<label for="formatted_address">postal_code:</label>
<input type="text" class="form-control" id="postal_code" name="postal_code" >
</div>
<div class="form-group">
<label for="formatted_address">PlaceId:</label>
<input type="text" class="form-control" id="Place_id" name="Place_id" >
</div>
</form>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions php_scripts/codesponsors_snippets/hours_to_cost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
# Hours to cost Calculation
# My hour cost is = 200
# Suppose I consider total hours 03:20:45

# Formula $total_cost = ($amount_per_hour*($consumed_hours*3600 + $consumed_mins*60 + $consumed_secs))/3600;

$h = 3; $m = 20; $s = 45;
$amount_per_hour = 200;
$consumed_hours = $h;
$consumed_mins = $m;
$consumed_secs = $s;

$total_cost = ($amount_per_hour*($consumed_hours*3600 + $consumed_mins*60 + $consumed_secs))/3600;


echo $total_cost;
Loading

0 comments on commit fc6fc41

Please sign in to comment.