Skip to content

Instantly share code, notes, and snippets.

View anilktechie's full-sized avatar
💭
I may be slow to respond.

ak anilktechie

💭
I may be slow to respond.
View GitHub Profile
@anilktechie
anilktechie / redshift.py
Created April 29, 2022 17:46 — forked from mmautner/redshift.py
Redshift Upserts w/ Python
import uuid
import psycopg2
from secret import REDSHIFT_CREDS
from secret import AWS_ACCESS_KEY, AWS_SECRET_KEY
def get_primary_keys(tablename, db):
c = db.cursor()
sql = "select indexdef from pg_indexes where tablename = '%s';" % tablename
c.execute(sql)
result = c.fetchall()[0][0]
@anilktechie
anilktechie / redshift_s3_util.py
Created March 15, 2022 15:25 — forked from laughingman7743/redshift_s3_util.py
redshift merge unload file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import gzip
import json
import os
from boto.s3.connection import S3Connection
from boto.s3.key import Key
import cStringIO
redshift=> SELECT DISTINCT column1 from test_table;
column1
---------
1
3
1
2
(4 rows)
import uuid
import psycopg2
from secret import REDSHIFT_CREDS
from secret import AWS_ACCESS_KEY, AWS_SECRET_KEY
def get_primary_keys(tablename, db):
c = db.cursor()
sql = "select indexdef from pg_indexes where tablename = '%s';" % tablename
c.execute(sql)
result = c.fetchall()[0][0]
#!/usr/bin/env bash
# This script clones all repos in a GitHub org
# It requires the GH CLI: https://cli.github.com
# It can be re-run to collect new repos and pull the latest changes
set -euo pipefail
USAGE="Usage: gh-clone-org <user|org>"
@anilktechie
anilktechie / bulk-clone
Created January 20, 2022 00:33 — forked from ahmadnassri/bulk-clone
bulk-clone with gh + jq
#!/bin/bash
USAGE="Usage: bulk-clone <mine|user|org> [name]"
[[ $# -eq 0 ]] && echo >&2 "missing arguments: ${USAGE}" && exit 1
# set protocol to ssh
gh config set git_protocol ssh -h github.com
# check if gh cli is installed
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN
(
SELECT table_name
FROM information_schema.tables
WHERE table_schema=current_schema()
)
@anilktechie
anilktechie / sugh.sh
Created December 31, 2021 07:33 — forked from erdincay/sugh.sh
su GitHub (downloading all repositories from a given user)
#!/bin/bash
if [ -z "$1" ]; then
echo "waiting for the following arguments: username + max-page-number"
exit 1
else
name=$1
fi
if [ -z "$2" ]; then
@anilktechie
anilktechie / wrapper.py
Created December 19, 2021 06:00 — forked from natyavidhan/wrapper.py
DiaryDB API Wrapper For Python
import requests
import json
class DiaryDB:
def __init__(self, name, api_key, url):
self.api_key = api_key
self.name = name
self.url = url
@anilktechie
anilktechie / database.py
Created December 19, 2021 06:00 — forked from TheDerpySage/database.py
Python SQLite Wrapper Class
import sqlite3
# A Self Contained Database Wrapper written for Admiral
class Database:
# Note: Primary Key ID's in SQLite start autoincrementing at 1
def __init__(self, name=None):
self.conn = None