Skip to content

Instantly share code, notes, and snippets.

View kristianperkins's full-sized avatar

Kristian Perkins kristianperkins

View GitHub Profile
@kristianperkins
kristianperkins / stop_ec2.py
Last active April 26, 2019 04:37
Stop all EC2 instances with the 'Stoppable': 'true' tag
#!/usr/bin/env python3
import boto3
s = boto3.Session(profile_name='profile')
ec2 = s.resource('ec2')
instances_to_stop_filter = [
{ 'Name':'tag:Stoppable', 'Values': ['true'] },
{ 'Name':'instance-state-name', 'Values': ['running'] }
@kristianperkins
kristianperkins / display_requests.py
Last active May 21, 2017 00:41
Display of python `requests` responses in jupyter notbooks
from IPython.display import display_html, display_javascript
import uuid
from jinja2 import Environment, BaseLoader
def display_request(r):
rq_id = str(uuid.uuid4())
rs_id = str(uuid.uuid4())
template = Environment(loader=BaseLoader()).from_string("""<div class='dr'>
{% if r.ok %}
<div class='dr_status dr_success' style='height: 24px; width: 100%; background-color: lightgreen;'>Successful response {{r.status_code}} for {{r.request.url}}</div>
@kristianperkins
kristianperkins / supervisord.sh
Created February 19, 2016 01:18 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@kristianperkins
kristianperkins / horoscope.py
Created August 30, 2015 23:16
display a random horoscope from the onion website
import random
from bs4 import BeautifulSoup
import requests
b = BeautifulSoup(requests.get('http://www.theonion.com/features/horoscope').text, 'html.parser')
astro = random.choice(b.findAll("li", {"class": "astro"}))
print(astro.find('div', {'class': 'large-thing'}).get_text())
@kristianperkins
kristianperkins / count.py
Created May 31, 2014 06:40
Obscure counting with the contextlib.contextmanager decorator
from contextlib import contextmanager
@contextmanager
def start_and_end():
print 1
yield
print 3
# prints 1, 2 and 3 in order
with start_and_end():
@kristianperkins
kristianperkins / README.md
Last active December 26, 2015 17:49
Conways Game of Live simulation for Minecraft mod ComputerCraft

This is a lua program that will run Conways Game of Life simulations for ComputerCraft. This code also runs in a unix shell (used for testing).

Glider Gun

This was written a fair while ago and could probably use some cleanup.

tell application "Google Chrome"
set windowList to every tab of every window whose URL starts with "https://mail.google.com"
repeat with tabList in windowList
set tabList to tabList as any
repeat with tabItr in tabList
set tabItr to tabItr as any
delete tabItr
end repeat
end repeat
end tell
#!/usr/bin/env ruby
require 'net/http'
require 'json'
gitlab_token = "YOUR TOKEN"
gitlab_uri = "URL GITLAB"
# number of repositories to display in the list
# order the list by the numbers
ordered = true