Skip to content

Instantly share code, notes, and snippets.

@karlkranich
karlkranich / cft-bucket-policy-conditional.json
Last active July 15, 2021 21:43
CloudFormation templates (json and yml) that conditionally include a user and a statement
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Bucket policy testing",
"Parameters": {
"ReadWriteUser": {
"Type": "String",
"Default": "",
"Description": "arn of read-write user to add to bucket policy"
},
"ReadOnlyUser": {
@karlkranich
karlkranich / multisheet-duplicate-finder.js
Last active May 30, 2021 13:52
Find duplicates across Google Sheets
/** Multisheet Duplicate Finder **
To use, paste this code into a Google Spreadsheets Apps Script (Tools - Script editor)
Loops through all of the sheets in the current spreadsheet.
Identifies duplicates in the chosen column.
Skips the chosen number of header rows.
Creates and alert box listing the duplicates, and colors the duplicate cells red.
The directive below limits the script to only be able to access this spreadsheet.
* @OnlyCurrentDoc
*/
@karlkranich
karlkranich / index.php
Created March 7, 2017 01:27
Google's PHP Quickstart adapted to use a service account
<?php
require_once __DIR__.'/vendor/autoload.php';
date_default_timezone_set('America/New_York');
define('SCOPES', implode(' ', array(
Google_Service_Sheets::SPREADSHEETS_READONLY)
));
<?php
require_once realpath(dirname(__FILE__) . '/vendor/autoload.php');
include_once "google-api-php-client/examples/templates/base.php";
$client = new Google_Client();
/************************************************
ATTENTION: Fill in these values, or make sure you
have set the GOOGLE_APPLICATION_CREDENTIALS
@karlkranich
karlkranich / apitest.php
Last active July 17, 2018 14:49
Updated PHP code to use the Google Sheets API. See usage instructions at http://karl.kranich.org/2015/04/16/google-sheets-api-php/ More examples at https://gist.github.com/karlkranich/afa39e3d778455b38c38
<?php
// apitest.php
// by Karl Kranich - karl.kranich.org
// version 3.1 - edited query section
require_once realpath(dirname(__FILE__) . '/vendor/autoload.php');
include_once "google-api-php-client/examples/templates/base.php";
$client = new Google_Client();
@karlkranich
karlkranich / sheets-api-test-part2.php
Last active February 2, 2023 21:39
(obsolete due to Google changes) PHP code to use the Google Spreadsheets API with an OAuth Service Account. For more info, see http://karl.kranich.org/google-sheets-api-php
<?php
// Section 5: edit a row
// You'll need to get the etag and row ID, and send a PUT request to the edit URL
$rowid = 'cre1l'; // got this and the etag from the table data output from section 3
$etag = 'NQ8VCRBLVCt7ImA.';
$url = "https://spreadsheets.google.com/feeds/list/$fileId/od6/private/full/$rowid";
$method = 'PUT';
$headers = ["Authorization" => "Bearer $accessToken", 'Content-Type' => 'application/atom+xml', 'GData-Version' => '3.0'];
$postBody = "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:gsx=\"http://schemas.google.com/spreadsheets/2006/extended\" xmlns:gd=\"http://schemas.google.com/g/2005\" gd:etag='&quot;$etag&quot;'><id>https://spreadsheets.google.com/feeds/list/$fileid/od6/$rowid</id><gsx:gear>phones</gsx:gear><gsx:quantity>6</gsx:quantity></entry>";
$req = new Google_Http_Request($url, $method, $headers, $postBody);