Skip to content

Instantly share code, notes, and snippets.

View kako-nawao's full-sized avatar

Claudio Omar Melendrez Baeza kako-nawao

  • Bahía Blanca, Argentina
View GitHub Profile
@kako-nawao
kako-nawao / tiled_grid_height.py
Last active October 16, 2016 13:47
Calculate the height for a row of images with different aspect ratios
def calculate_tiled_row_height(row_width, space_width, num_images, sum_aspect)
"""
Calculate the height required for a row of tiled images based on the row width,
space between images, number of images and sum of aspect ratios of images.
"""
return (row_width - (num_images - 1) * space_width) / float(sum_aspect)
def get_image_rows(image_iter, row_width, row_min_aspect, space_width):
"""
@kako-nawao
kako-nawao / factory_superclass.py
Last active April 11, 2017 22:07
Example of a factory superclass, which constructor returns a new instance of the correct subclass for a given parameter.
class Animal(object):
def __new__(cls, common_name, *args, **kwargs):
for subclass in cls.__subclasses__():
if subclass.common_name == common_name:
return object.__new__(subclass, *args, **kwargs)
raise ValueError('No animal species matched for common name "{}"'.format(common_name))
@kako-nawao
kako-nawao / sonar-project.properties
Created February 22, 2016 16:43
SonarQube project properties sample
# Main SonarQube project information
sonar.projectKey=com.example:some-project
sonar.projectName=some-project
sonar.projectVersion=0.0.1
# Source is everything minus typical django project and venv/ (CI server)
sonar.sources=.
sonar.exclusions=manage.py,tracker/**,apps/**/migrations/**,static/libs/**,venv/**
# Report paths (test results and coverage)
@kako-nawao
kako-nawao / init.sls
Last active October 14, 2016 23:31
SaltStack states for SonarQube scanner
# SonarQube continuous inspection scanner
include:
- core.unzip
sonar-scanner-download:
cmd.run:
- name: curl -L https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.zip -o {{ pillar['auth']['home'] }}/sonar-scanner-2.5.zip
- creates: {{ pillar['auth']['home'] }}/sonar-scanner-2.5.zip