Skip to content

Instantly share code, notes, and snippets.

View odeke-em's full-sized avatar

Emmanuel T Odeke odeke-em

View GitHub Profile
@odeke-em
odeke-em / demo.c
Last active December 11, 2021 20:17
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/types.h>
int main() {
char *name = "the_file_c.txt";
FILE *wf = fopen(name, "w");
@odeke-em
odeke-em / periodic_auto_refresh.py
Created February 7, 2020 11:33
A Transaction drop-in replacement to deal with the need for refreshing Cloud Spanner every 10 seconds
# Copyright 2020 Google LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""
The code in this file provides a drop-in replacement for spanner_v1.Transaction,
but one that auto-refreshes every 8.5 seconds, to deal with Cloud Spanner's server's
max idle time of 10 seconds, per:
@odeke-em
odeke-em / auto_refreshing_transaction.py
Created February 4, 2020 23:01
Auto-refreshing transaction prototype to take care of Spanner 10 second idle limit https://cloud.google.com/spanner/docs/reference/rest/v1/TransactionOptions#idle-transactions
# Copyright 2020 Google LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
import threading
import time
from google.cloud import spanner_v1 as spanner
@odeke-em
odeke-em / ddl_txn_bad_mix.py
Created February 2, 2020 22:56
Exhibit to show that DDL and Transactions don't mix thus transactions have to be implicitly committed first
#!/usr/bin/env python3
from google.cloud import spanner_v1 as spanner
def get_instance(client):
ins = client.instance('django-tests')
fresh_instance = False
if not ins.exists():
ins.configuration_name = 'projects/appdev-soda-spanner-staging/instanceConfigs/regional-us-west2'
@odeke-em
odeke-em / RESULTS.md
Last active February 3, 2020 18:57
Snippet to demonstrate why we should be encouraging customers to send batch update_ddl instead of one by one

Unbatched

$ time python3 foo.py 
real	10m6.379s
user	0m0.612s
sys	0m0.174s

Batched

package main
import (
"io/ioutil"
"math"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
BenchmarkClient-4 10000 134785 ns/op 3492 B/op 49 allocs/op
BenchmarkClient-4 10000 119346 ns/op 3490 B/op 49 allocs/op
BenchmarkClient-4 10000 126705 ns/op 3488 B/op 49 allocs/op
BenchmarkClient-4 10000 119080 ns/op 3488 B/op 49 allocs/op
BenchmarkClientServer-4 10000 106035 ns/op 4985 B/op 65 allocs/op
BenchmarkClientServer-4 10000 106615 ns/op 4983 B/op 65 allocs/op
BenchmarkClientServer-4 10000 106463 ns/op 4982 B/op 65 allocs/op
BenchmarkClientServer-4 10000 109390 ns/op 4983 B/op 65 allocs/op
BenchmarkClientServerParallel4-4 30000 76569 ns/op 7906 B/op 76 allocs/op
BenchmarkClientServerParallel4-4 30000 844355 ns/op 7979 B/op 78 allocs/op
@odeke-em
odeke-em / traced-opencv-example.py
Created May 5, 2018 07:39
Tracing an OpenCV tutorial app with OpenCensus Python
#!/usr/bin/env python3
"""
Copyright 2018, OpenCensus Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
u may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@odeke-em
odeke-em / server.go
Last active April 14, 2019 09:49
elcacher
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@odeke-em
odeke-em / main.py
Created April 22, 2018 03:39
Crawler using requests and memcached both trace instrumented with OpenCensus
#!/usr/bin/env python3
"""
Copyright 2018, OpenCensus Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
u may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0