Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
wehappyfew / GitHub curl.sh
Created February 2, 2016 12:36
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl --header 'Authorization: token INSERTACCESSTOKENHERE' \
--header 'Accept: application/vnd.github.v3.raw' \
--remote-name \
--location https://api.github.com/repos/owner/repo/contents/path
# Example...
TOKEN="INSERTACCESSTOKENHERE"
OWNER="BBC-News"
REPO="responsive-news"
@wehappyfew
wehappyfew / change_default_gh_branch.py
Last active September 15, 2020 14:16
Change the default branch of a GH repo. I use it with CodeDeploy in order to deploy different branch each time. Enjoy.
import json,requests,pprint
gh_url = "https://api.github.com"
username = 'wehappyfew'
# a token is needed for 2 Factor Auth, otherwise only Name/Pass
custom_token = 'blablablablablablabla' # a custom personal token from GitHub
repo_name = 'your_repo_name'
new_default_branch = 'something' # this is going to change every time
#encode to JSON
@wehappyfew
wehappyfew / CodeDeploy Policy
Last active January 28, 2016 09:11 — forked from flomotlik/CodeDeploy Policy
This policy provides the entity that is attached to [IAM user] , with the rights to actually create new application revisions, create new deployments, update the deployment configuration and get the status of a deployment. The following snippet for CodeDeploy sets the minimum required rights. Please note, that you need to adapt the snippet to yo…
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codedeploy:RegisterApplicationRevision",
"codedeploy:GetApplicationRevision"
],
"Resource": [
@wehappyfew
wehappyfew / change_jenkins_branch.py
Created December 28, 2015 15:11
Chnage the branch in Jenkins dynamically
def create_jenkins_xml_config(github_username =None,
repo_name = None,
juser = None,
jpass = None,
j_xml_url =None,
filename = None,
new_branch_name = None):
"""
The function reads the jenkins config.xml , saves it and changes the branch name.
[Then, the file with the updated branch name is ready to be posted back.]
@wehappyfew
wehappyfew / new_jenkins_job.py
Last active June 15, 2018 15:55
Create a new Jenkins job using Python requests library
__author__ = 'wehappyfew'
import requests
def create_new_jenkins_job(j_url, j_port, new_job_name, j_user, j_pass):
"""
Create a new jenkins job
:param j_url: eg http://mysite.com
:param j_port: eg 8686 [8080 is jenkin's default]
def check_if_process_is_alive(process_name):
"""
Enter a process name and check if it is in the running processes on a UNIX system
:param process_name:
:return:
"""
import os
from subprocess import check_output
@wehappyfew
wehappyfew / RDS.py
Last active September 14, 2015 19:21
Connect to RDS and create a read replica of a specific db instance
__author__ = 'wehappyfew'
# http://boto.readthedocs.org/en/latest/ref/rds.html#boto.rds.RDSConnection.create_dbinstance_read_replica
from AWS_project import us_east_1
import boto.rds, os, sys
if os.name == "nt": #if I run it on WIN
from AWS_project import aws_secret_access_key, aws_access_key_id
RDSconn = boto.rds.connect_to_region(us_east_1,
@wehappyfew
wehappyfew / apend_path_on_runtime.py
Last active September 8, 2015 12:07
The python project is in Jenkin's workspace folder. I want to run a python script on the QA server (Linux).The workspace folder's path must be added (on runtime for now) in the sys.path .That way I can make imports into the script from any module of the project. TODO->For a more permanent solution the path must be hardcoded in a var in the machine.
__author__ = 'wehappyfew'
import sys,os,pprint
# check the sys.path before I add my directory
print("1: -- ",sys.path)
if os.name == "posix": # check if the script runs on Linux
# If I comment it out, it will throw ImportError
# This path should always be appended on runtime,
def make_POST(live, arg1, arg2, variable_arg):
"""
"""
import requests
payload = {
"arg1_key" : arg1,
"arg2_key" : arg2
}
@wehappyfew
wehappyfew / update_R53.py
Last active February 22, 2019 04:12
Grab the ips of the newly spawned EC2 instances based on their tag and update their hostnames on Route 53
from my_AWS_credentials import aws_access_key_id,aws_secret_access_key
import boto.route53
from boto.route53.record import ResourceRecordSets
import boto.ec2
import itertools
EC2conn = boto.ec2.connect_to_region(region_name = "us-east-1",
aws_access_key_id = aws_access_key_id,
aws_secret_access_key = aws_secret_access_key)
def fetch_host_ips(EC2conn, tag, state):