Skip to content

Instantly share code, notes, and snippets.

View bindiego's full-sized avatar
🎸
be cool

Bin Wu bindiego

🎸
be cool
View GitHub Profile
@bindiego
bindiego / bq_dataaccess_view.sql
Last active May 30, 2022 23:45
GCP Billing export to BigQuery and Datastudio Visualization
SELECT
timestamp AS Date,
resource.labels.project_id AS ProjectId,
protopayload_auditlog.serviceName AS ServiceName,
protopayload_auditlog.methodName AS MethodName,
protopayload_auditlog.status.code AS StatusCode,
protopayload_auditlog.status.message AS StatusMessage,
protopayload_auditlog.authenticationInfo.principalEmail AS UserId,
protopayload_auditlog.servicedata_v1_bigquery.jobCompletedEvent.job.jobName.jobId AS JobId,
protopayload_auditlog.servicedata_v1_bigquery.jobCompletedEvent.job.jobConfiguration.query.query AS Query,
# ___ ___ __ __
# / | __ ______/ (_) /_____/ /
# / /| |/ / / / __ / / __/ __ /
# / ___ / /_/ / /_/ / / /_/ /_/ /
# /_/ |_\__,_/\__,_/_/\__/\__,_/
#
# Linux Audit Daemon - Best Practice Configuration
# /etc/audit/audit.rules
# Remove any existing rules
@bindiego
bindiego / binwu.go
Created August 30, 2019 10:24
Golang get fully qualified domain name / hostname
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"bytes"
//"time"
)
@bindiego
bindiego / download_data.sh
Last active August 27, 2019 04:18
Google Cloud pub/sub hello world
#!/bin/bash -ex
gsutil cp gs://cloud-training-demos/sandiego/sensor_obs2008.csv.gz .
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bindiego
bindiego / firebase_bigquery_dedup.sql
Last active February 28, 2023 14:29
BigQuery Deduplication
with n_dups as
(
SELECT event_name, event_timestamp, user_pseudo_id, count(1)-1 as n_duplicates
FROM `project.dataset.events_20190610`
group by event_name, event_timestamp, user_pseudo_id
)
select n_duplicates, count(1) as n_cases
from n_dups
group by n_duplicates
order by n_cases desc
@bindiego
bindiego / readme.md
Created August 14, 2019 09:44
Check storage performance with dd

Check storage performance with dd

Tests

One process reading from $MY_DISK

dd if=$MY_DISK of=/dev/null bs=1MiB count=200 iflag=nocache
#!/bin/bash
apt-get update || true
ROLE=$(/usr/share/google/get_metadata_value attributes/dataproc-role)
if [[ "${ROLE}" == 'Master' ]]; then
apt-get install -y vim
else
# something that goes only on worker nodes
@bindiego
bindiego / create_table.sh
Last active August 7, 2019 09:59
Google Cloud BigQuery sample schema for clickstream events
#!/bin/bash
pwd=`pwd`
bq mk --table bindiego:click_stream.events $pwd/schema.json
@bindiego
bindiego / syslog.md
Last active February 17, 2019 10:50
configure syslog as central logging server

Server

Edit file /etc/rsyslog.conf

 # provides UDP syslog reception
 module(load="imudp")
 input(type="imudp" port="514")

 # provides TCP syslog reception