Skip to content

Instantly share code, notes, and snippets.

@multidis
multidis / list_as_fun_args.r
Created December 16, 2013 22:21
Passing lists as function arguments in R. Frequently helps reduce code repetition (e.g. if/else calls of different functions with mostly the same arguments). NOTE: always consider a closure function as FP alternative to this method of dealing with repetitive code elements.
## regular case
foo <- function(a, b, c) a + b - c ## does something
foo2 <- function(b, c) b + c ## also some function
foo(a=1, b=2, c=5)
foo2(b=2, c=5) ## repeating list of multiple arguments
## passing a list
arg.list <- list(b=2, c=5)
do.call(foo, c(list(a=1), arg.list))
do.call(foo2, arg.list)
@multidis
multidis / aws_s3_ls.sh
Last active March 22, 2024 07:30
List of files in a specific AWS S3 location in a shell script.
#!/bin/bash
# setup AWS CLI first
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html
# configure AWS CLI (e.g. use IAM role for S3 access)
export AWS_DEFAULT_REGION=us-east-1
export AWS_ACCESS_KEY_ID=IDHERE
export AWS_SECRET_ACCESS_KEY=KeyHere
@multidis
multidis / coinbase_pro_fills.py
Created February 28, 2024 07:43
Coinbase Pro fills statement export does not work as of Feb 2024 (just in time for tax prep!). Infinite wheel on the front-end, 500 status response from the API. Old Pro API still works and allows exporting fills to compute taxable transactions.
## Problem
## https://www.reddit.com/r/CoinBase/comments/18b1oqe/comment/krtzg2n/
## As a workaround, use old API (as of 2024-02)
## https://github.com/danpaquin/coinbasepro-python
## (Python 3.7) pip install cbpro
import json
import cbpro
# supply API credentials
auth_client = cbpro.AuthenticatedClient(key, secret, passphrase)
@multidis
multidis / Dockerfile
Last active September 15, 2021 12:24
Cron job scheduling inside a Docker container.
# phusion baseimage initiates cron properly
# Use phusion/baseimage as base image. To make your builds reproducible, make
# sure you lock down to a specific version, not to `latest`!
# See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for
# a list of version numbers.
FROM phusion/baseimage:0.9.16
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
@multidis
multidis / video_cut.sh
Last active August 24, 2020 04:34
Cut a portion of video file by timestamps without re-encoding.
## https://superuser.com/a/377407
## starting second (7) to ending timestamp (06:05:00)
ffmpeg -ss 7 -i input.mkv -to 06:05:00 -c copy output.mkv
@multidis
multidis / all_aws_lambda_modules_python.md
Created February 29, 2020 01:50 — forked from gene1wood/all_aws_lambda_modules_python.md
AWS Lambda function to list all available Python modules for Python 2.7 3.6 and 3.7

This gist contains lists of modules available in

in AWS Lambda.

It also contains the code to run in Lambda to generate these lists. In addition there is a less_versbose module in the code that you can call to get a list of the top level modules installed and the version of those modules (if they contain a version

# IMPORTS
import pandas as pd
import math
import os.path
import time
from bitmex import bitmex
from binance.client import Client
from datetime import timedelta, datetime
from dateutil import parser
from tqdm import tqdm_notebook #(Optional, used for progress-bars)
@multidis
multidis / split_strat_scale.r
Created December 23, 2013 08:17
Stratified sampling: training / test data split preserving class distribution (caret functions) and scaling (standardize) the data. Stratified folds for CV.
library(caret)
## select training indices preserving class distribution
in.train <- createDataPartition(yclass, p=0.8, list=FALSE)
summary(factor(yclass))
ytra <- yclass[in.train]; summary(factor(ytra))
ytst <- yclass[-in.train]; summary(factor(ytst))
## standardize features: training parameters of scaling for test-part
Xtra <- scale(X[in.train,])
@multidis
multidis / bobp-python.md
Created February 27, 2019 21:11 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@multidis
multidis / julia_parallel_multicore.jl
Last active May 30, 2018 06:58
Multicore computations in Julia language.
# start julia specifying how many cores to make available
##$ julia -p 4
# julia multicore start command in a shell script
##$ julia -p $(nproc)
# http://stackoverflow.com/questions/2314750/how-to-assign-the-output-of-a-shell-command-to-a-variable
# alternatively add local cores dynamically (e.g. after starting julia single-core)
##$ julia
addprocs_local(3)