Skip to content

Instantly share code, notes, and snippets.

View MCardus's full-sized avatar

Marc Cardús MCardus

View GitHub Profile
@MCardus
MCardus / thread_pool_skeleton.py
Last active October 17, 2016 14:16
Thread pool skeleton for Python
#Code based in @dgorissen script from stackoverflow
import os
from subprocess import call
from Queue import Queue
from threading import Thread
class Worker(Thread):
"""Thread executing tasks from a given tasks queue"""
def __init__(self, tasks):
Thread.__init__(self)
@MCardus
MCardus / ubuntu_provision_base.sh
Created July 3, 2017 08:08
Ubuntu base provisioning. It installs base packets, python pip, ansible and git
# Ubuntu base provisioning
# It installs base packets, python pip, ansible and git
# Upgrade system
sudo apt-get update && sudo apt-get -y upgrade
# Install essential packages
sudo apt-get install -y build-essential python git libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libffi-dev
@MCardus
MCardus / provision_docker_ubuntu16.sh
Created July 3, 2017 08:43
Provision Docker in Ubuntu 16. It installs docker and configure current user to being able to acces docker without sudo
# Provision Docker Ubuntu 16
# It installs docker and configure current user to being able to acces docker without sudo
#Docker user
USER=$(whoami)
#Install Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
@MCardus
MCardus / doc2vec_training.txt
Created July 4, 2017 09:54
doc2vec_training
def trainModel(inputPath: String) = {
log.info("Training model from data in path: " + inputPath)
val file: File = new File(inputPath)
val iter = new BasicLineIterator(file)
val cache = new AbstractCache[VocabWord]
val tokenizer = new DefaultTokenizerFactory
tokenizer.setTokenPreProcessor(new CommonPreprocessor)
try {
_paragraphVectors = new ParagraphVectors.Builder().minWordFrequency(1).iterations(5).epochs(1).layerSize(100).learningRate(0.025).windowSize(5).iterate(iter).trainWordVectors(false).vocabCache(cache).tokenizerFactory(tokenizer).sampling(0).build
@MCardus
MCardus / logging_properties.yml
Last active February 28, 2018 11:23
Python logging conf in YML format for generaing JSON logs
version: 1
formatters:
human:
format: |
{
"name" : "%(name)s",
"timestamp" : "%(asctime)s",
"severity" : "%(levelname)s",
"message" : "%(message)s"
}
from functools import reduce
class MyData(object):
def __init__(self, data):
self.data = data
def get_data(self):
return self.data
import unittest
class DummyTestCase(unittest.TestCase):
def setUp(self):
self.my_data = [1,2,3,4,5]
def test_length(self):
self.assertEqual(len(self.my_data),5)
def tearDown(self):
@MCardus
MCardus / logging_conf.py
Last active March 12, 2018 16:04
Python logging util reading conf from a yml file
import os
import yaml
import logging
import logging.config
import functools
import json
def setup_logging(
default_path= 'logging_properties.yml',
default_level=logging.DEBUG,
@MCardus
MCardus / config
Created December 30, 2021 15:23
ssh config profile
Host *
User mcardus
IdentityFile ~/.ssh/id_rsa
@MCardus
MCardus / .zshrc
Last active March 2, 2022 13:35
zshrc profile
# ZSHRC #
## ZSH CONF ##
### Mac OS Home ###
export HOME="/Users/$(whoami)"
export ZSH=$HOME"/.oh-my-zsh"
ZSH_THEME="agnoster"