Skip to content

Instantly share code, notes, and snippets.

@ivansabik
ivansabik / parse_epoch_microsecond_redshift.sql
Last active April 22, 2025 21:48
Parse UNIX timestamp (epoch) with microsecond precision in Redshift (e.g. data generated by Debezium)
-- Replace hardcoded value with a column
-- Outputs 2025-04-21 18:14:26.308930
select DATEADD(
microsecond,
1745259266308930 % 1000000,
timestamp 'epoch' + (1745259266308930 / 1000000) * interval '1 second'
)
@ivansabik
ivansabik / example_lambda_sns_to_slack.py
Last active April 22, 2025 21:48
Example implementation lambda for Monitoring of DMS Tasks on Slack from https://www.linkedin.com/pulse/monitoring-dms-tasks-slack-ruchi-khanuja
import json
import urllib3
http = urllib3.PoolManager()
def lambda_handler(event, context):
"""
Example payload:
{
@ivansabik
ivansabik / Dockerfile
Created October 14, 2021 16:18
Install fb prophet in docker python:3.7-stretch
# Install prophet
FROM python:3.7-stretch
RUN apt-get -y install git libc-dev
RUN pip install pip==19.1.1
WORKDIR /opt
RUN git clone https://github.com/facebook/prophet.git
@ivansabik
ivansabik / rds_export.py
Created June 9, 2021 21:14
rds_export.py
import boto3
def lambda_handler(event, context):
client.start_export_task(
ExportTaskIdentifier="",
SourceArn="arn:aws:rds:us-east-1:",
S3BucketName="",
IamRoleArn=",
KmsKeyId="",
S3Prefix="rds-exports",
@ivansabik
ivansabik / compare_files_in_dir.py
Last active May 5, 2017 23:51
Compares md5 hashes for files in two directories recursively. It will compare using one dir as base (the left one) against the other one (the right one).
import argparse
import hashlib
import os
def get_checksum(f):
md5 = hashlib.md5()
md5.update(open(f).read())
return md5.hexdigest()
@ivansabik
ivansabik / print_sqlalchemy_query_mysql.py
Created February 2, 2017 18:35
Print SQLAlchemy query_MySQL
# http://nicolascadou.com/blog/2014/01/printing-actual-sqlalchemy-queries/
from sqlalchemy.dialects import mysql; print str(query.statement.compile(dialect=mysql.dialect()))
@ivansabik
ivansabik / add_alias.sh
Last active November 10, 2015 16:00
Add permanent alias for CLI
#!/bin/bash
echo "alias cls='clear'" >> ~/.bash_aliases && source ~/.bash_aliases
@ivansabik
ivansabik / soundcloudPlaylistScrape.js
Created October 10, 2015 18:39
Scrape soundcloud playlist with casperjs and slimerjs then save to text file
var casper = require('casper').create();
var fs = require('fs');
casper.start('https://soundcloud.com/vlad-gonta/sets/new-1', function() {
this.viewport(768, 10000);
}).then(function () {
this.scrollToBottom();
this.wait(1000);
}).then(function () {
this.scrollToBottom();
@ivansabik
ivansabik / iconv_convert_all_mp4_to_mp3.sh
Last active August 29, 2015 14:24
Iconv convert all mp4 in a folder to mp3
#!/bin/sh
for i in *.m4a; do avconv -i "$i" "${i/.m4a/.mp3}"; done
@ivansabik
ivansabik / alerta-cnsf
Last active August 29, 2015 14:18
Ejemplo node-app para ejecutar al iniciar Ubuntu
#!/bin/sh
# Source: https://github.com/chovy/node-startup/blob/master/init.d/node-app
# author: Anthony Ettinger (chovy)
NODE_ENV="development"
PORT="3000"
APP_DIR="~/scripts-startup"
NODE_APP="cnsf.js"
CONFIG_DIR="$APP_DIR"