Skip to content

Instantly share code, notes, and snippets.

View rickcrawford's full-sized avatar

Rick Crawford rickcrawford

View GitHub Profile
@rickcrawford
rickcrawford / README.md
Last active May 8, 2021 00:08
List roles/permissions for a project

Create a virtual environment

python3 -m venv .venv
source .venv/bin/activate

Install requirements

@rickcrawford
rickcrawford / bucket.py
Last active April 27, 2021 15:55
Creating a global bucket and then creating a logging sink
from google.cloud.logging_v2.types import logging_config
from google.cloud.logging_v2.services.config_service_v2 import ConfigServiceV2Client
from google.protobuf.field_mask_pb2 import FieldMask
#FYI - https://realpython.com/python-f-strings/ for "f"
REGION = "global"
PROJECT_ID = "rjc-testing-project"
BUCKET_ID="my-bucket-id"
@rickcrawford
rickcrawford / README.md
Last active May 11, 2020 22:18
Reporting on your network settings based on the APIs available here: https://cloud.google.com/vpc/docs/apis

This file script is provided without any warrantees and is for testing purposes.

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
@rickcrawford
rickcrawford / network_report.py
Created May 11, 2020 22:13
Reporting on your network settings based on the APIs available here: https://cloud.google.com/vpc/docs/apis
import sys
import json
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
def get_forwarding_rules(service, project):
@rickcrawford
rickcrawford / main.go
Created August 30, 2019 15:32
HTTP3 server example.
package main
import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"os"
"sync"
@rickcrawford
rickcrawford / download.sh
Created October 23, 2018 05:08
Complaint data processing scripts
# The following file downloads complaint data from the Consumer Finance Board.
URL="https://data.consumerfinance.gov/api/views/s6ew-h6mp/rows.csv?accessType=DOWNLOAD"
FILE=complaints.csv
if [ ! -f $FILE ]; then
echo "-- Downloading file --"
curl -L $URL --output $FILE
fi
python process.py complaints.csv
@rickcrawford
rickcrawford / dataflow.py
Created September 6, 2018 16:39
Launch a dataflow template reference
from __future__ import print_function
from apiclient.discovery import build
from oauth2client import service_account
import httplib2
# https://cloud.google.com/dataflow/docs/templates/executing-templates#example-1-custom-template-batch-job
# https://cloud.google.com/dataflow/docs/reference/rest/v1b3/projects.templates/launch
# https://cloud.google.com/dataflow/docs/templates/executing-templates#using-gcloud
projectId = "my-project-id"
@rickcrawford
rickcrawford / AgentTest.cs
Created July 10, 2018 19:50
Agent Client using credentials json file in .NET for Dialogflow
using System;
using Xunit;
using System.IO;
using Google.Cloud.Dialogflow.V2;
using Grpc.Core;
using Google.Apis.Auth.OAuth2;
using Grpc.Auth;
namespace dialogflowtest
{
@rickcrawford
rickcrawford / elastic_search_golang.md
Last active July 22, 2020 00:03
Get Elastic Search client working locally with Golang

Create 2 files: main.go and docker-compose.yml. Once both are created use docker-compose up and it will build the necessary files and start Elastic Search.

I found it necessary to add elastic.SetSniff(false) or I could not connect. Also remember the docker containers have security enabled for Elasticsearch with the password set as elastic:changeme. You can test it using curl:

curl http://127.0.0.1:9200/_cat/health -u elastic:changeme

Once it is running you can successfully run the main.go file using go run main.go.

@rickcrawford
rickcrawford / gcs_create_and_read_pubsub.md
Created November 27, 2017 03:42
Create a GCS topic if it doesn't exist, then creates messages

Checks if a topic exists. If it doesn't it will be created. Next it will create messages on that topic with a new subscription.

package main

import (
	"context"
	"log"
	"time"