Skip to content

Instantly share code, notes, and snippets.

View tankist's full-sized avatar

Victor Gryshko tankist

View GitHub Profile
@tankist
tankist / bash_aws_jq_cheatsheet.sh
Created June 8, 2021 11:25 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create a Lambda function that will take a comma seperated list of key=value pairs and return an array of key value pairs that can then be used in cloudformation tags resource parameter"
Resources:
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create a Lambda function that will take a comma seperated list of key=value pairs and return an array of key value pairs that can then be used in cloudformation tags resource parameter"
Resources:
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create a Lambda function that will take a comma seperated list of key=value pairs and return an array of key value pairs that can then be used in cloudformation tags resource parameter"
Resources:
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
@tankist
tankist / vm-resize-hard-disk.md
Created October 2, 2015 13:54 — forked from christopher-hopper/vm-resize-hard-disk.md
Resize a Hard Disk for a Virtual Machine provisioned using Vagrant from a Linux base box to run using VirutalBox.

Resize a Hard Disk for a Virtual Machine

Our Virtual Machines are provisioned using Vagrant from a Linux base box to run using VirutalBox. If the Hard Disk space runs out and you cannot remove files to free-up space, you can resize the Hard Disk using some VirtualBox and Linux commands.

Some assumptions

The following steps assume you've got a set-up like mine, where:

<?php
$basePrices = [
"6,00 € /l" => ['price' => '6,00', 'volume' => '1', 'unit' => 'l'],
"1.88 € / 100 g" => ['price' => '1.88', 'volume' => '100', 'unit' => 'g'],
"1.15 € / 100 gr" => ['price' => '1.15', 'volume' => '100', 'unit' => 'gr'],
"2.33 € / 1 kg" => ['price' => '2.33', 'volume' => '1', 'unit' => 'kg'],
"2.33 € / kg" => ['price' => '2.33', 'volume' => '1', 'unit' => 'kg'],
"0,70 € / 10St" => ['price' => '0,70', 'volume' => '10', 'unit' => 'St'],
"2.49 € / Stück" => ['price' => '2.49', 'volume' => '1', 'unit' => 'Stück'],
@tankist
tankist / pp1_algo.md
Last active August 29, 2015 14:04
PP1 algorithm description

PP1 API main algorithm

Proportions

  1. Reorder APIs by country order (position per country)
  2. Calculate Sum of all weights per PP (or per country) s = w1 + w2 + ... + wn;
  3. Calculate proportion for each source: p1 = w1 / s, p2 = w2 / s, ...., pn = wn / s (save as original APIs proportions)
  4. Normalize proportions to desired items per page (default is 48): nP1 = p1 * 48, nP2 = p2 * 48, ...., nPn = pn * 48
  5. For each API:
    • If normalized proportion < 0.5, then multiply ipp by 2 (for instance if ebay wants 12 items to be displayed, then request 24 items)
INSERT INTO portal_parameters_map (portal_id, portal_parameter_id, parameter_value)
SELECT id AS portal_id, (SELECT id from portal_parameters WHERE code = 'uservoice_code') AS portal_parameter_id, uservoice_code AS parameter_value
FROM runashop_priceportal.main_data m
WHERE m.uservoice_code <> '' AND m.uservoice_code IS NOT NULL AND m.id IN (SELECT id FROM `portals_migration`)
UNION SELECT id AS portal_id, (SELECT id from portal_parameters WHERE code = 'chartbeat_code') AS portal_parameter_id, chartbeat_code AS parameter_value
FROM runashop_priceportal.main_data m
WHERE m.chartbeat_code <> '' AND m.chartbeat_code IS NOT NULL AND m.id IN (SELECT id FROM `portals_migration`)
{
"type": "DEBUG",
"message": {
"_id": "5384c31a8c4d07.12935603",
"_timestamp": 1401209630,
"_date": "2014-05-27 19:53:50",
"common_exceptions": [
"Exception: Property \"p\" is empty in Z:\\home\\runashop.lan\\phalcon\\app\\services\\MultiTracking.php (104)",
"Exception: Empty ads in Z:\\home\\runashop.lan\\phalcon\\app\\services\\Ad.php (128)"
],
@tankist
tankist / ads.php
Last active January 1, 2016 18:19
Proposed migrations fix
<?php
use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Mvc\Model\Migration;
class AdsMigration_1010 extends Migration
{
const TABLE_NAME = 'ads';