Skip to content

Instantly share code, notes, and snippets.

View ryanmats's full-sized avatar

Ryan Matsumoto ryanmats

View GitHub Profile
@ryanmats
ryanmats / Google Cloud Platform Identity-Aware-Proxy (IAP) code sample
Last active February 6, 2018 19:20
Shows how to authenticate to an Identity-Aware-Proxy protected application on GCP using a service account and PHP code.
/**
* Make a request to an application protected by Identity-Aware Proxy.
*
* @param string $url The Identity-Aware Proxy-protected URL to fetch.
* @param string $clientId The client ID used by Identity-Aware Proxy.
*
* @return The response body.
*/
function make_iap_request($url, $clientId, $pathToServiceAccount)
{
@ryanmats
ryanmats / Program.cs
Last active March 16, 2018 20:36
Program.cs File - Calling SnapshotAsync on Collection Reference
using CommandLine;
using Google.Cloud.Firestore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GoogleCloudSamples
{
public class QuickStartFirestoreProgram
{
@ryanmats
ryanmats / QuickStartFirestore.csproj
Created March 16, 2018 20:36
QuickStartFirestore.csproj - Calling SnapshotAsync on Collection Reference
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<StartupObject>GoogleCloudSamples.QuickStartFirestoreProgram</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
<PackageReference Include="Google.Cloud.Firestore" Version="1.0.0-beta02" />
</ItemGroup>
@ryanmats
ryanmats / gist:59cc0567b93317dc857c112b556a9349
Created March 16, 2018 20:38
Calling SnapshotAsync on Collection Reference - Error Message
Unhandled Exception: System.InvalidOperationException: Shutdown has already been called
at Grpc.Core.Internal.CompletionQueueSafeHandle.BeginOp()
at Grpc.Core.Internal.CallSafeHandle.StartReceiveMessage(IReceivedMessageCallback callback)
at Grpc.Core.Internal.AsyncCallBase`2.ReadMessageInternalAsync()
at Grpc.Core.Internal.ClientResponseStream`2.<MoveNext>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Linq.AsyncEnumerable.<ForEachAsync_>d__174`1.MoveNext()
@ryanmats
ryanmats / gist:04a49f75b8806550175a8d8542d2d0fb
Created March 16, 2018 20:40
Calling GetSnapshotAsync on Collection Reference - Error Message
Program.cs(77,53): error CS1061: 'CollectionReference' does not contain a definition for 'GetSnapshotAsync' and no extension method 'GetSnapshotAsync' accepting a first argument of type 'CollectionReference' could be found (are you missing a using directive or an assembly reference?) [/Users/ryanmats/testing/dotnet-docs-samples/firestore/api/QuickStartFirestore/QuickStartFirestore.csproj]
The build failed. Please fix the build errors and run again.
@ryanmats
ryanmats / gist:7efc444b9214dbab149d54f7fd446381
Created March 19, 2018 09:35
C# Firestore - UpdateAsync with Nested Fields Dot Notation - Error Message
Unhandled Exception: System.AggregateException: One or more errors occurred. (Status(StatusCode=InvalidArgument, Detail="Entity has a nested entity property named 'Favorites' as well as a property prefixed with 'Favorites.', this results in name collision.")) ---> Grpc.Core.RpcException: Status(StatusCode=InvalidArgument, Detail="Entity has a nested entity property named 'Favorites' as well as a property prefixed with 'Favorites.', this results in name collision.")
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass0_0`2.<<WithRetry>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Cloud.Firestore.WriteB
using CommandLine;
using Google.Cloud.Firestore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GoogleCloudSamples
{
public class QuickStartFirestoreProgram
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<StartupObject>GoogleCloudSamples.QuickStartFirestoreProgram</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
<PackageReference Include="Google.Cloud.Firestore" Version="1.0.0-beta02" />
</ItemGroup>
require "google/cloud/firestore"
firestore = Google::Cloud::Firestore.new
frank_ref = firestore.doc "users/frank"
frank_ref.set({
name: "Frank",
favorites: {
food: "Pizza",
color: "Blue",
subject: "Recess"
},
require "google/cloud/firestore"
firestore = Google::Cloud::Firestore.new(project_id: project_id)
cities_ref = firestore.col "cities"
query = cities_ref
query.get do |document_snapshot|
puts "Deleting document #{document_snapshot.document_id}."
document_ref = document_snapshot.ref
document_ref.delete