Skip to content

Instantly share code, notes, and snippets.

@pavelanni
pavelanni / solarize.sh
Created March 13, 2017 22:41 — forked from codeforkjeff/solarize.sh
shell script for setting gnome-terminal color palette to use Solarized theme
#!/bin/sh
#
# Shell script that configures gnome-terminal to use solarized theme
# colors. Written for Ubuntu 11.10, untested on anything else.
#
# Solarized theme: http://ethanschoonover.com/solarized
#
# Adapted from these sources:
# https://gist.github.com/1280177
# http://xorcode.com/guides/solarized-vim-eclipse-ubuntu/
@pavelanni
pavelanni / naming_sequence.yml
Last active December 20, 2017 03:56
Create sequential file names or EC2 instance tags with Ansible
---
- name: naming sequence
connection: local
hosts: localhost
vars:
- names: ['cs','cs','cs','cs','cs',]
- numbers: []
- n_instances: 5
@pavelanni
pavelanni / ping-led.py
Last active January 20, 2018 20:30
This Raspberry Pi script pings a specific host and if it's up it turns the LED on
#!/usr/bin/env python3
#
# This script pings a site specified in the command line and
# turns the LED on if the site is on. It should be run as root because
# it uses sockets in the ping implementation below.
#
# Code for ping below is borrowed from https://gist.github.com/pyos/10980172
#
import time
import random
@pavelanni
pavelanni / dynamodb_types.py
Created January 31, 2018 18:47
DynamoDB field types
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("users")
response = table.get_item()
response = table.get_item(Key={
'user_id': 'REDACTED',
'user_name': 'John'
})
for k in response['Item'].keys():
@pavelanni
pavelanni / bashrc.sh
Created February 26, 2018 15:15
This changes PS1 on the AWS EC2 instance to show the instance's name (instead of the meaningless internal hostname)
# Borrowed from here: https://stackoverflow.com/questions/18338585/how-to-get-the-instance-name-from-the-instance-in-aws
# This requires AWS CLI to be installed in the instance
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
INSTANCE_NAME=`aws ec2 describe-tags --filters Name=resource-id,Values=$INSTANCE_ID --query Tags[].Value --output text`
export PS1="[\u@$INSTANCE_NAME \W]\\$ "
@pavelanni
pavelanni / russian_decor.py
Created February 26, 2018 15:26
Fun with decorators and Russian language in Python
печать = print
def пожалуйста(func):
def wrapper():
func()
печать(', пожалуйста ', end='')
return wrapper
@pavelanni
pavelanni / s3_glacier_archive.py
Last active June 7, 2018 17:32
Lambda function to automatically copy objects uploaded to S3 bucket to a Glacier vault. It also creates a record in DynamoDB for each archived object so they can be retrieved later
import urllib.parse
import boto3
import tempfile
from datetime import datetime
account_id = 'XXXXXXXXXX'
db_name = 'archive-db'
vault = 'archive-vault'
@pavelanni
pavelanni / gist:bc3aba097ffd30647125602f3cba5153
Created July 22, 2020 16:10
List packages in each RPM repo and store in files
for r in $(dnf repolist | egrep -v "^repo" | awk '{print $1}') ; do dnf repository-packages ${r} list > ${r}.txt ; done
#!/usr/bin/env python
import sys
import sqlite3
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <year_start> <year_end>")
sys.exit(1)
year_start = int(sys.argv[1])
year_end = int(sys.argv[2])
@pavelanni
pavelanni / gist:800a1de2d7c85881b751868208f1d5e3
Created March 12, 2021 15:54
Python: Add items to a dict from a second dict without changing the existing ones
d1 = {'a': 1, 'b': 2, 'c': 3}
d2 = {'d': 4, 'e': 5, 'a': 6}
d1.update({k:v for (k,v) in d2.items() if k not in d1})
d1
# Out: {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}