Skip to content

Instantly share code, notes, and snippets.

# Bash best practices and style-guide
Just simple methods to keep the code clean.
Inspired by [progrium/bashstyle](https://github.com/progrium/bashstyle) and [Kfir Lavi post](http://www.kfirlavi.com/blog/2012/11/14/defensive-bash-programming/).
## Quick big rules
* All code goes in a function
* Always double quote variables
# Source: https://gist.github.com/vfarcic/78c1d2a87baf31512b87a2254194b11c
###############################################################
# How To Create A Complete Internal Developer Platform (IDP)? #
# https://youtu.be/Rg98GoEHBd4 #
###############################################################
# Additional Info:
# - DevOps MUST Build Internal Developer Platform (IDP): https://youtu.be/j5i00z3QXyU
# - How To Create A "Proper" CLI With Shell And Charm Gum: https://youtu.be/U8zCHA-9VLA
@actionjack
actionjack / gist:c7923ba533be096fb7a72b061c508cba
Created August 15, 2023 14:29 — forked from gmhawash/gist:4043232
Reset jenkins password
0. SSH to server
1. Edit /opt/bitnami/apps/jenkins/jenkins_home/config.xml
2. set userSecurity to false: <userSecurity>false</userSecurity>
3. delete
<authorizationStrategy> and <securityRealm>
4. /etc/init.d/bitnami restart
@actionjack
actionjack / create_sparse_file.sh
Created March 13, 2023 13:14 — forked from CMCDragonkai/create_sparse_file.sh
CLI: Creating Sparse Files (Can be used for virtual loopback block devices)
#!/usr/bin/env bash
# seems to work on any filesystem
# final size is (bs * seek) in bytes
# this creates a 4MB sparse file
dd if=/dev/zero of=/tmp/file bs=1 count=0 seek=4194304
# or
@actionjack
actionjack / lambda_function.py
Created November 29, 2022 21:06 — forked from yuyasugano/lambda_function.py
image tweet with S3 in Lambda
import os
import sys
import uuid
import boto3
import tweepy
from urllib.parse import unquote_plus
# Twitter authentication variables
consumer_key = os.environ.get('TWITTER_CONSUMER_KEY', 'ap-northeast-1')
consumer_secret = os.environ.get('TWITTER_CONSUMER_SECRET', 'ap-northeast-1')
@actionjack
actionjack / debug_requests.py
Created September 30, 2022 15:07 — forked from Daenyth/debug_requests.py
Enable debug logging for python requests
import requests
import logging
import httplib
# Debug logging
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
req_log = logging.getLogger('requests.packages.urllib3')
req_log.setLevel(logging.DEBUG)
AWS_ROOT_CA_FILE=$HOME/aws.root.ca.bundle.pem
cp /dev/null $AWS_ROOT_CA_FILE
for ca in \
https://www.amazontrust.com/repository/AmazonRootCA1.pem \
https://www.amazontrust.com/repository/AmazonRootCA2.pem \
https://www.amazontrust.com/repository/AmazonRootCA3.pem \
https://www.amazontrust.com/repository/AmazonRootCA4.pem \
https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem; do
@actionjack
actionjack / killAllBuilds.groovy
Created March 16, 2022 15:38 — forked from brandonfl/killAllBuilds.groovy
Kill all build and remove queued ones
import java.util.ArrayList;
import hudson.model.*;
def q = Jenkins.instance.queue
for (queued in Jenkins.instance.queue.items) {
q.cancel(queued.task)
}
for (job in Jenkins.instance.items) {
stopJobs(job)
@actionjack
actionjack / how-to-git-patch-diff.md
Created March 9, 2022 09:49 — forked from nepsilon/how-to-git-patch-diff.md
How to generate and apply patches with git? — First published in fullweb.io issue #33

How to generate and apply patches with git?

It sometimes happen you need change code on a machine from which you cannot push to the repo. You’re ready to copy/paste what diff outputs to your local working copy.

You think there must be a better way to proceed and you’re right. It’s a simple 2 steps process:

1. Generate the patch:

git diff &gt; some-changes.patch
@actionjack
actionjack / Jenkinsfile.groovy
Created February 21, 2022 09:47 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"