Skip to content

Instantly share code, notes, and snippets.

View andrewdoss-bit's full-sized avatar

andrewdoss-bit

View GitHub Profile
@andrewdoss-bit
andrewdoss-bit / Query.java
Created November 29, 2022 02:12
bit.io JDBC connection test
import java.sql.*;
import java.util.Properties;
public class Query {
// Note that the 'username/db_name' must use a '.' instead of a '/' for JDBC
private static final String url =
"jdbc:postgresql://db.bit.io/dliden.2020_Census_Reapportionment";
public static void main(String[] args) {
Properties props = new Properties();
@andrewdoss-bit
andrewdoss-bit / json_upload.py
Created February 17, 2022 02:49
Upload json with only requests
import requests
import io
import json
data = {"a": 1, "b": "world"}
buffer = io.StringIO()
json.dump(data, buffer)
buffer.seek(0)
url = 'https://import.bit.io/doss/json_upload/example'
@andrewdoss-bit
andrewdoss-bit / import_with_bitdotio.py
Created February 17, 2022 01:09
Example import with bitdotio Python package
import bitdotio
# Connect to bit.io
b = bitdotio.bitdotio(<YOUR_BITIO_KEY>)
# Download demo csv here:
# https://raw.githubusercontent.com/bitdotioinc/connection_snippets/main/video-game-sales.csv
# Upload to 'my_new_repo' with table name 'video_game_sales_csv'
with open('video-game-sales.csv', 'r', encoding='utf-8') as f:
b.create_import_file(f, 'my_new_repo', 'video_game_sales_csv')
@andrewdoss-bit
andrewdoss-bit / import_example.py
Created February 17, 2022 01:06
Python import example
import requests
with open("$PATH_TO_FILE", 'rb') as f:
data = f.read()
url = 'https://import.bit.io/$USERNAME/$REPO_NAME/$TABLE_NAME'
headers = {
"Content-Disposition": "attachment;filename='test.csv'",
"Authorization": "Bearer $TOKEN"
@andrewdoss-bit
andrewdoss-bit / local_db_test.go
Created December 28, 2021 20:52
pgx connection function benchmarks
package database
import (
"testing"
)
func BenchmarkConnWithName(b *testing.B) {
for i := 0; i < b.N; i++ {
ConnWithName()
}
@andrewdoss-bit
andrewdoss-bit / local_db.go
Last active December 28, 2021 20:56
pgx connection functions (with and without app name, with and without pool)
package database
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
)
@andrewdoss-bit
andrewdoss-bit / main-deploy.yaml
Last active September 30, 2021 01:18
Continuous deployment
name: Main Deploy
on:
push:
branches:
- main
jobs:
extract-transform-load:
runs-on: ubuntu-latest
env:
PG_CONN_STRING: ${{ secrets.PG_CONN_STRING }}
name: Pull Request Test
on:
pull_request:
branches:
- main
jobs:
extract-transform-load:
runs-on: ubuntu-latest
env:
PG_CONN_STRING: ${{ secrets.PG_CONN_STRING }}
@andrewdoss-bit
andrewdoss-bit / json_query.sql
Created September 28, 2021 16:02
Sample JSON query
SELECT *
FROM "doss/demo_repo"."json_demo"
WHERE (json_object_data) ->> 'Name' = 'Wii Sports'
@andrewdoss-bit
andrewdoss-bit / sample.json
Created September 28, 2021 15:59
Sample JSON
[
{"id": 1,
"json_object_data": {
"Rank": 1,
"Name": "Wii Sports",
"Platform": "Wii",
"Year": 2006,
"Genre": "Sports",
"Publisher": "Nintendo",
"NA_Sales": 41.49,