Skip to content

Instantly share code, notes, and snippets.

View waqashassan98's full-sized avatar

Waqas Hassan waqashassan98

View GitHub Profile
@waqashassan98
waqashassan98 / googlesheets.php
Last active November 23, 2020 09:00
Access Google Sheets via API in PHP, using Server to Server OAUTH
<?php
$root_path = '/path/to/your/root/';
require_once($root_path.'vendor/autoload.php');
define('APPLICATION_NAME', 'Google Sheets Importer');
define('APP_CREDENTIALS_PATH', $root_path.'service-account-2fb0dd3da332.json');// The Json file's path that you received via service account
define('SCOPES',
@waqashassan98
waqashassan98 / ontraport_mail_merge_api.php
Created January 28, 2018 16:23
Edit Ontraport Emails using Ontraport API
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/mailmerge/vendor/autoload.php';
use OntraportAPI\Ontraport;
//live
$key = "tbpy9FUGu9XXXX";
$appid = "2_9614_MnlYYYY";
@waqashassan98
waqashassan98 / dynamic_css.php
Created January 28, 2018 15:53
Headers for creating Dynamic CSS using PHP
$expires = 5*60*60*24; // how long to cache in secs..
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header('Content-type: text/css');
@waqashassan98
waqashassan98 / ffmpeg-conversions.php
Last active January 28, 2018 15:49
Cron Job to convert Videos to MP4 and WebM using ffmpeg library. It uses file locking to prevent duplicate cron jobs being running simultaneously
<?php
$f = fopen('lock', 'w') or die ('Cannot create lock file');
if (flock($f, LOCK_EX | LOCK_NB)) {
ini_set('max_execution_time', 0);
/**
Database Configurations
**/
@waqashassan98
waqashassan98 / create_and_send_csv_as_email_attachment.php
Created January 28, 2018 15:36
Dynamically create CSV and send as attachment in emails
function send_csv_mail($data, $body, $to = 'email@example.com', $subject = 'Website Report', $from = 'waqashassan98@gmail.com') {
if (!$fp = fopen('php://temp', 'w+')) echo "unable to create csv";
foreach ($data as $row)
{
fputcsv($fp, $row);
}
rewind($fp);
$csvData = stream_get_contents($fp);
@waqashassan98
waqashassan98 / bookings_in_date_range_woocommerce_bookings.php
Created January 28, 2018 14:56
This function can be used to get the booking details in a date range from Woocommerce Bookings plugin
get_bookings_in_date_range_wh( $next_monday, $next_friday, $product_id, true );
function get_bookings_in_date_range_wh( $start_date, $end_date, $product_or_resource_id = 0, $check_in_cart = true ) {
$args = array(
'status' => get_wc_booking_statuses(),
'object_type' => 'product_or_resource',
'date_between' => array(
'start' => $start_date,
'end' => $end_date,
),