Skip to content

Instantly share code, notes, and snippets.

View knil-sama's full-sized avatar
💭
Nothing really

Clement Demonchy knil-sama

💭
Nothing really
View GitHub Profile
$('#global_sentiment').html(' <p>Debug @remove count good : '+response["count_good"]+' count neutral : '+response["count_neutral"]+' count bad : '+response["count_bad"]+'</p> \
<div class="progress">\
<div class="progress-bar progress-bar-success" role="progressbar" style="width:'+response["pourcent_good"]+'%">\
Positive\
</div>\
<div class="progress-bar progress-bar-warning" role="progressbar" style="width:'+response["pourcent_neutral"]+'%">\
Neutral\
</div>\
<div class="progress-bar progress-bar-danger" role="progressbar" style="width:'+response["pourcent_bad"]+'%">\
Negative\
def unjsonify(data) -> dict:
"""
Convert binary to json
Args:
data: Binary json returned by Flask
Returns:
str:
"""
return json.loads(data.decode('utf-8'))
import boto3
def creation_table_scaling(table_name: str, key_name: str, key_type: str, max_read_capacity: int, max_write_capacity: int):
"""
Create table dynamodb and make it scale then wait for it to be created
Args:
table_name (str): the name of the table to create
key_name (str): the name of the key, and main attribute of the table
key_type (str): the data type for the attribute, S for string, N for number, B for binary
max_read_capacity(int) : Max nb of read per minute
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName='fake_table',
KeySchema=[ { 'AttributeName': 'id_key', 'KeyType': 'HASH' }, ],
AttributeDefinitions=[ { 'AttributeName': 'id_key', 'AttributeType': 'S' }, ],
ProvisionedThroughput={ 'ReadCapacityUnits': 10, 'WriteCapacityUnits': 10 } )
import boto3
autoscaling_client = boto3.client('application-autoscaling')
#Read capacity
autoscaling_client.register_scalable_target(ServiceNamespace='dynamodb',
ResourceId='table/fake_table',
ScalableDimension='dynamodb:table:ReadCapacityUnits',
MinCapacity=5,
MaxCapacity=100)
#Write capacity
autoscaling_client.register_scalable_target(ServiceNamespace='dynamodb',
import boto3
autoscaling_client = boto3.client('application-autoscaling')
percent_of_use_to_aim_for = 50.0
scale_out_cooldown_in_seconds = 60
scale_in_cooldown_in_seconds = 60
autoscaling_client.put_scaling_policy(ServiceNamespace='dynamodb',
ResourceId='table/fake_table',
PolicyType='TargetTrackingScaling',
PolicyName='ScaleDynamoDBReadCapacityUtilization',
import boto3
autoscaling_client = boto3.client('application-autoscaling')
percent_of_use_to_aim_for = 50.0
scale_out_cooldown_in_seconds = 60
scale_in_cooldown_in_seconds = 60
autoscaling_client.put_scaling_policy(ServiceNamespace='dynamodb',
ResourceId='table/fake_table',
PolicyType='StepScaling',
StepScalingPolicyConfiguration={
@knil-sama
knil-sama / all_test.py
Created February 14, 2018 13:50
Automated test suite in python unittest
import unittest
from tests.test_aggregation_logic import AggregationLogicTestCase
from tests.test_api_mock import TestApi
from tests.test_commons import CommonsTestCase
def listing_test_class(suite: unittest.TestSuite, test_class):
[suite.addTest(test_class(func)) for func in dir(test_class) if func.startswith("test_")]
return suite
sudo yum install -y python34 python34-pip httpd-tools
sudo python3 -m pip install pypiserver passlib
# input password manualy for this one
htpasswd -sc htpasswd.txt data-packages-user
mkdir ~/packages
# need to be root, sudo didn't work do sudo su
echo "
description 'A minimal PyPI server for use with pip/easy_install.'
author 'Clement Demonchy'
start on runlevel [2345]
@knil-sama
knil-sama / clean_unknown_pods_k8s
Created May 7, 2018 12:34
clean unknown pods on kubernetes
kubectl get pods | awk '$3 == "Unknown" { print $1 }' | xargs kubectl delete pods --grace-period=0 --force