Skip to content

Instantly share code, notes, and snippets.

@atika
atika / ask.sh
Last active August 29, 2015 14:08
This is a general-purpose function to ask Yes/No questions in Bash, either with or without a default answer.
#!/bin/bash
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
@atika
atika / bash_colors.sh
Created November 8, 2014 13:47
Display a matrice of Bash Colors in the terminal
#!/bin/bash
T='gYw'
echo -e "\n 40m 41m 42m 43m 44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' ' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m\033[$BG \033[0m";
done
#!/bin/bash
if [ ! -d "/DisabledExtensions/AMD6000Controller.kext" ]; then
sudo mkdir /DisabledExtensions 2>/dev/null
sudo mv /System/Library/Extensions/{AMD6000Controller.kext,AMDFramebuffer.kext,AMDRadeonX3000.kext,AMDRadeonX3000GLDriver.bundle,AMDSupport.kext} /DisabledExtensions/
echo "Disable AMD Drivers Kext (Moved to /DisabledExtensions)"
else
sudo mv /DisabledExtensions/* /System/Library/Extensions/
echo "AMD Drivers restored to System Extensions"
fi
@atika
atika / template.sh
Last active August 29, 2015 14:08
Simple content generator from a template file and variables. Replace variables on a file with bash. I use it for an html email template.
#!/bin/bash
template_path="$1"
function usage (){
echo -e "Usage: template <path to template> 'var1|content' 'var2|content'...";
[[ -f "$template_path" ]] && { echo "Current variables:" $(cat $template_path |perl -ne '/#([A-Za-z1-9]+)#[^#].*/ && printf "%s, ", $1'); }
exit 1;
}
@atika
atika / dropzone.sublime-snippet
Created November 10, 2014 20:42
Dropzone 3 action snippet for Sublime Text
<snippet>
<content><![CDATA[
# Dropzone Action Info
# Name: ${1:Name}
# Description: ${2:Description}
# Handles: ${3:Files, Text}
# Creator: ${4:Creator Name}
# URL: ${5:Creator URL}
# OptionsNIB: ${6:Login, ExtendedLogin, APIKey, UsernameAPIKey, ChooseFolder, ChooseApplication, GoogleAuth}
# LoginTitle: ${7:Login Title (For Login NIB)}
@atika
atika / git-sync-upstream.sh
Created December 23, 2014 20:11
Update a GitHub Forked Repository with his Upstream/Master (and update remote master)
#!/bin/bash
# usage: git-sync-upstream "/your/git/folder/" [rebase/merge]
action="merge"
if [ $# -ge 1 ]; then cd "$1"; fi
if [ $# -eq 2 ]; then if [ "$2" = "rebase" ]; then action="rebase"; fi; fi
clear;
@atika
atika / apache-selfsigned-cert-gen.sh
Last active August 29, 2015 14:13
Self-Signed Certificate for Apache
#!/bin/bash
servername=$(echo "$@" |sed 's/ /-/g')
if [ "$servername" == "" ]; then
echo "Please specify a server name like: myserver.com"
exit
fi
if [ -f "$servername.key" ] || [ -f "$servername.crt" ]; then
@atika
atika / checkisup
Created April 4, 2015 10:01
Check until host is up using PING
# Check until host is UP
checkisup () { while (true) do if ping -t 2 -c 1 $1 &>/dev/null; then echo -e " $(date +%T) \\033[1;36m Host $1 is up! \\033[0m\n $(ping -c 1 $1 | head -n2 | tail -n1)"; return 0; else echo -e " $(date +%T) \\033[31m Host $1 is down...\\033[0m"; sleep 1; fi; done; }
@atika
atika / split_quicktime_movie.scpt
Created May 22, 2015 10:15
Split a QuickTime video in multiple part (set cut mark in seconds)
# Split and export a QuickTime Movie
# Create a folder "exports" on the desktop
# Open one movie file in QuickTime
# Configure where you want to cut the video, if you want first and last part and the QuickTime window name (after modification)
# Launch this script and wait
#------------- BEGIN OF CONFIGURATION --------
-- Middle Mark : Set where you want to cut the video (in seconds)
@atika
atika / github-open-url.sh
Created October 21, 2015 08:34
Alias to open a GitHub URL from a Git Repo
github-open-url='git remote -v | grep fetch | grep -oE '\''https://github.com/\S+'\'' | xargs -I{} open {}'