Skip to content

Instantly share code, notes, and snippets.

@marshyski
marshyski / base.html
Created November 3, 2014 22:42
base.html template for flask-template-requests.py
{% block body %}
<body>
<center>
{% for line in result %}
{{ line }}
{% endfor %}
</center>
</body>
{% endblock %}
@marshyski
marshyski / marshyski-health.py
Last active August 29, 2015 14:08
marshyski.com health check
#!/usr/bin/python
import requests
from bs4 import BeautifulSoup
requests.packages.urllib3.disable_warnings()
urls = [
'http://marshyski.com/',
'http://marshyski.com/man-behind-the-keyboard/',
@marshyski
marshyski / fabfile-socket.py
Last active August 29, 2015 14:11
Fabric checking for port 22 socket connection
from fabric.api import sudo, env, put
import configuration as config
import socket, time
env.hosts = open('hosts_file', 'r').readline().rstrip()
env.user = config.USERNAME
env.port = '22'
env.key_filename = config.KEY_FILE
env.warn_only = True
@marshyski
marshyski / JenkinsService.groovy
Created January 27, 2015 19:42
Creating Jenkins Folder via web request with Grails / REST
import grails.plugins.rest.client.RestBuilder
import grails.transaction.Transactional
import sun.misc.BASE64Encoder
@Transactional
class JenkinsService {
def grailsApplication
def createJob(String folderName) {
String url = grailsApplication.config.jenkins.url
@marshyski
marshyski / xl-deploy-api-examples
Created February 6, 2015 22:21
Xebia Labs XL Deploy API Examples with cURL
curl -XPOST 'http://<xld-server>:<xld-port>/deployit/repository/ci/Applications/<ci>' --user 'some_username:some_password' -H "Content-type:application/xml" -d '<core.Directory id="Applications/ci"/>'
@marshyski
marshyski / customs-tags.rb
Last active August 29, 2015 14:15
Creating Puppet Facts by AWS EC2 Tags with a proxy
#Set proxy before we try to talk to AWS API
ENV["http_proxy"] ||= 'http://proxy:port'
ENV["https_proxy"] ||= 'http://proxy:port'
ENV["NO_PROXY"] ||= '127.0.0.1, localhost, 169.254.169.254'
#Make 1 EC2 API call and put the output on a dot file in /tmp/.tags
region = Facter.value('region')
instanceid = Facter.value('instanceid')
%x{/usr/bin/aws --region #{region} --output text ec2 describe-instances --instance-ids #{instanceid} | grep "TAGS" | awk '{ print $2 " " $3 " " $4}'| tr [:upper:] [:lower:] > /tmp/.tags }.chomp
@marshyski
marshyski / gist:484e81cd865ad0b2ee18
Created March 17, 2015 18:38
Chocolately Cheat Sheet
# List repo sources
choco sources list
# Setup local server
choco sources add -name local -source http://fqdn
choco sources disable chocolately
# Install package
choco install 7zip
choco install 7zip -source http://fqdn
@marshyski
marshyski / docker-maintenance.sh
Last active August 29, 2015 14:17
Docker Operations and Maintenance
# Delete all docker images
for x in `docker images | grep -v REPO | awk '{ print $3 }'`; do docker rmi $x; done
# Delete all docker containers
for x in `docker ps -a | grep -v CONTAINER | awk '{ print $1 }'`; do docker rm -f $x; done
# Start all docker containers
for x in `docker ps -a | grep -v CONTAINER | awk '{ print $1 }'`; do docker start $x; done
# Fresh docker env in Redhat flavors
@marshyski
marshyski / wait_https.py
Created April 20, 2015 17:56
Wait for website listening on port 443 to become available
import configuration as config
from subprocess import call
import requests
import time, socket
''' Turn off SSL errors '''
requests.packages.urllib3.disable_warnings()
''' Wait for port 443 is listening '''
while True:
@marshyski
marshyski / getinfo.sh
Last active August 29, 2015 14:19
System Info RHEL/CentOS 7
#!/bin/bash
env && echo
runlevel && echo
hostname -f && echo
cat /etc/hosts && echo