Skip to content

Instantly share code, notes, and snippets.

View JamieCressey's full-sized avatar

Jamie Cressey JamieCressey

  • GameSparks
  • United Kingdom
View GitHub Profile
public class FlattenedMapEntry {
String key;
String value;
}
public static List<FlattenedMapEntry> flattenMap(String parent, Map<?, ?> map) {
List<FlattenedMapEntry> results = new ArrayList<>();
for (Object o : map.entrySet()) {
@JamieCressey
JamieCressey / local_server.py
Created August 5, 2017 15:54
Local Development Server for AWS SAM - used with CodeStar Projects
import imp
import yaml
from bottle import Bottle
def get_yaml():
with open("template.yml", 'r') as stream:
string = ''
for line in stream.readlines():
string += line.replace('!', '')
@JamieCressey
JamieCressey / gist:2c2e3f6e63f3119ddf1ad6aab02a3e14
Created February 19, 2017 20:43
Reallocate unassigned ElasticSearch Shards
#!/usr/bin/env python
import requests
import random
from time import sleep
def get_cluster_nodes():
nodes = []
resp = requests.get('http://localhost:9200/_nodes').json()
@JamieCressey
JamieCressey / gist:3cafb3d64ab2047612ef1fbbaa11a4c5
Created December 12, 2016 16:33
Python Boto script that returns the number of AWS EC2 instances not covered by a Reserved Instance
#!/usr/bin/env python3
import boto3
import json
def get_reserved_instances(client):
resp = {}
ris = client.describe_reserved_instances(
Filters=[{'Name': 'state', 'Values': ['active', ]}])
@JamieCressey
JamieCressey / dict_to_dynamodb_item.py
Created April 24, 2016 20:56
Coverts a standard Python dictionary to a Boto3 DynamoDB item
def dict_to_item(raw):
if type(raw) is dict:
resp = {}
for k,v in raw.iteritems():
if type(v) is str:
resp[k] = {
'S': v
}
elif type(v) is int:
resp[k] = {
@JamieCressey
JamieCressey / dynamodb_item_to_dict.py
Last active June 30, 2021 11:49
Coverts a Python Boto3 DynamoDB item to a standard dictionary
def parse_dynamo_item(item):
resp = {}
if type(item) is str:
return item
for key,struct in item.iteritems():
if type(struct) is str:
if key == 'I':
return int(struct)
else:
return struct
@JamieCressey
JamieCressey / gist:f5e011cb838b9d867834
Created December 17, 2015 19:33
Keepalived Ubuntu init script
#! /bin/sh
#
# keepalived LVS cluster monitor daemon.
#
# Written by Andres Salomon <dilinger@voxel.net>
#
### BEGIN INIT INFO
# Provides: keepalived
# Required-Start: $syslog $network $remote_fs
# Required-Stop: $syslog $network $remote_fs
@JamieCressey
JamieCressey / gist:6f12f4c25f67b614003f
Created July 10, 2014 12:01
Pseudocode BTCJam Bot
$investments = curl(https://btcjam.com/api/v1/listings?appid=[APP ID]&secret=[APP Secret]) \\ you get the idea
foreach($investments as $investment) {
if(!$db->query(FIND THIS INVESTMENT IN MY DB)){
curl(https://btcjam.com/api/v1/investments&listing_id=$investment['id']&amount=0.000001);
$db->insert(WE HAVE INVESTED!);
}else{
continue;
}
}
// Everything is explained here:
// https://github.com/kuzetsa/gekko/blob/master/docs/Configuring_gekko.md
var config = {};
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// GENERAL SETTINGS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Gekko stores historical history