Skip to content

Instantly share code, notes, and snippets.

View ikobi12's full-sized avatar

Ivan ikobi12

  • Amsterdam
View GitHub Profile
@ikobi12
ikobi12 / set_env_vars_from_env_file
Created October 30, 2023 10:22
[heroku] Heroku
heroku config:set $(awk -F'=' '{print $1"="$2}' <env_file>) -a <app_name?
@ikobi12
ikobi12 / download_file.py
Created October 17, 2022 15:36
[boto3] boto3 #python #aws
s3 = boto3.client('s3')
with open('FILE_NAME', 'wb') as f:
s3.download_fileobj('BUCKET_NAME', 'OBJECT_NAME', f)
@ikobi12
ikobi12 / column_selector_in_pipeline.py
Created January 26, 2022 14:12
[sklearn] Sklearn #python #ml #sklearn
from sklearn.compose import ColumnTransformer, make_column_selector
from sklearn.pipeline import Pipeline
col_name_pattern = "feature_"
pl = Pipeline([
(
"col_selector",
ColumnTransformer([
("selector", "passthrough", make_column_selector(pattern=col_name_pattern))
], remainder="drop")
@ikobi12
ikobi12 / capture_logs_in_test_cases.py
Created November 22, 2021 11:09
[unittest] Python's Unittest #python #unittest #nose2
"""
The issue is that the unittest runner replaces sys.stdout/sys.stderr before the testing starts, and the StreamHandler is still writing to the original sys.stdout.
"""
import sys
import unittest
import logging
logger = logging.getLogger()
logger.level = logging.DEBUG
/*
If counts are more than one, then there are either duplicates or it is not the correct business key
This will also return the content of rows
*/
select *
from (
select *
, count(1) over (
partition by <BK>
) as cn
select ordinal_position,
column_name,
data_type,
case when character_maximum_length is not null
then character_maximum_length
else numeric_precision end as max_length,
is_nullable,
column_default as default_value
from information_schema.columns
where table_name = 'batch_logger' -- enter table name here
@ikobi12
ikobi12 / kubectl_cheat_sheet.sh
Last active January 28, 2021 15:09
[Kubernetes] Kubernetes cheat sheet #kubectl #kubernetes
# Get commands
kubectl get services # List all services in the namespace
kubectl get deployment my-dep # List a particular deployment
kubectl get replicaset # List all replica sets
kubectl get pods # List all pods in the namespace
kubectl get pods -o wide # List all pods in the current namespace, with more details
kubectl get pod my-pod -o yaml # Get a pod's YAML
# Describe commands
kubectl describe nodes my-node
@ikobi12
ikobi12 / view_users_and_permissions.sql
Created January 25, 2021 14:18
[PostgreSQL] Postgres DB queries and tips #postgres #sql
SELECT r.rolname, r.rolsuper, r.rolinherit,
r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,
r.rolconnlimit, r.rolvaliduntil,
ARRAY(SELECT b.rolname
FROM pg_catalog.pg_auth_members m
JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)
WHERE m.member = r.oid) as memberof
, r.rolreplication
, r.rolbypassrls
FROM pg_catalog.pg_roles r
@ikobi12
ikobi12 / assume_role_from_console_with_mfa.sh
Last active January 20, 2021 13:40
[AWS CLI] AWS command line utils and notes #aws #awscli
# if there is a MFA set up for the account
# you can use this script to assume a role
#!/bin/sh
export AWS_PROFILE=my_profile
ACCOUNT_ID=2128506 # production account id
TEST_ACCOUNT_ID=666420
TEST_ACCOUNT_ROLE=testDataEngineerRole
USERNAME=bg
@ikobi12
ikobi12 / range.js
Created August 23, 2020 12:04
[JavaScript] Useful JS snippets #js #javascript
function range(stopAt, startAt = 0) {
return [...Array(stopAt).keys()].map(i => i + startAt);
}