Skip to content

Instantly share code, notes, and snippets.

@luizbraga
luizbraga / collection_size.py
Created October 4, 2017 14:43
List collections, size and count of documents on MongoDB
from pymongo import MongoClient
MONGO_URI = ''
DATABASE_NAME = ''
client = MongoClient(MONGO_URI)
db = client[DATABASE_NAME]
collections = db.collection_names()
def readable_size(file_size):
@anschaef
anschaef / bootstrap-4-sass-mixins-cheat-sheet.scss
Last active April 12, 2024 08:49
Bootstrap 4 Sass Mixins [Cheat sheet with examples]
/* -------------------------------------------------------------------------- */
// All Bootstrap 4 Sass Mixins [Cheat sheet]
// Updated to Bootstrap v4.5.x
// @author https://anschaef.de
// @see https://github.com/twbs/bootstrap/tree/master/scss/mixins
/* -------------------------------------------------------------------------- */
/*
// ########################################################################## */
// New cheat sheet for Bootstrap 5:
@hmldd
hmldd / scroll.py
Last active August 8, 2024 23:41
Example of Elasticsearch scrolling using Python client
# coding:utf-8
from elasticsearch import Elasticsearch
import json
# Define config
host = "127.0.0.1"
port = 9200
timeout = 1000
index = "index"
@kevinzakka
kevinzakka / data_loader.py
Last active March 16, 2025 18:14
Train, Validation and Test Split for torchvision Datasets
"""
Create train, valid, test iterators for CIFAR-10 [1].
Easily extended to MNIST, CIFAR-100 and Imagenet.
[1]: https://discuss.pytorch.org/t/feedback-on-pytorch-for-kaggle-competitions/2252/4
"""
import torch
import numpy as np
@tomsing1
tomsing1 / luigi_first_steps.md
Last active June 19, 2024 21:52
First steps with the Luigi workflow manager

First steps with the Luigi workflow manager

As an introduction into Luigi, I am following this tutorial with some modifications, e.g. installation using conda.

The problems and solutions described in the examples below have led to the development of sciluigi,

@jfeala
jfeala / batch.py
Created April 18, 2017 12:33
AWS Batch wrapper for Luigi
"""
AWS Batch wrapper for Luigi
From the AWS website:
AWS Batch enables you to run batch computing workloads on the AWS Cloud.
Batch computing is a common way for developers, scientists, and engineers
to access large amounts of compute resources, and AWS Batch removes the
undifferentiated heavy lifting of configuring and managing the required
@jayant91089
jayant91089 / pyspark-virtualenv-jupyter-ubuntutahr-setup.md
Last active December 15, 2018 12:54
Describes how to setup spark 2.1.0 for use with python (pyspark) via jupyter notebook. Does not assume root access. Uses virtualenv.

Get prebuilt spark

mkdir spark_install && cd spark_install
wget http://d3kbcqa49mib13.cloudfront.net/spark-2.1.0-bin-hadoop2.7.tgz
tar -xzvf spark-2.1.0-bin-hadoop2.7.tgz 
cd spark-2.1.0-bin-hadoop2.7/

Test prebuilt spark (this should open a spark console, use Ctrl+C to exit )

@ruzickap
ruzickap / aws_create_site.yml
Created February 16, 2017 12:35
Ansible playbook which creates instances and tag volumes
---
- name: Create Instance in AWS
hosts: localhost
connection: local
gather_facts: false
vars:
aws_access_key: "xxxxxx"
aws_secret_key: "xxxxxx"
security_token: "xxxxxx"
@deehzee
deehzee / psycopg2_sshtunnel.py
Last active January 16, 2025 15:22
How to Connect To PostgreSQL Using SSHTunnelForwarder and Psycopg2
import psycopg2
from sshtunnel import SSHTunnelForwarder
# For interactive work (on ipython) it's easier to work with explicit objects
# instead of contexts.
# Create an SSH tunnel
tunnel = SSHTunnelForwarder(
('128.199.169.188', 22),
ssh_username='<username>',
@henriquebastos
henriquebastos / 00-detect-virtualenv-sitepackages.py
Last active October 17, 2022 04:22
IPython startup script to detect and inject VIRTUAL_ENV's site-packages dirs.
"""IPython startup script to detect and inject VIRTUAL_ENV's site-packages dirs.
IPython can detect virtualenv's path and injects it's site-packages dirs into sys.path.
But it can go wrong if IPython's python version differs from VIRTUAL_ENV's.
This module fixes it looking for the actual directories. We use only old stdlib
resources so it can work with as many Python versions as possible.
References:
http://stackoverflow.com/a/30650831/443564