Skip to content

Instantly share code, notes, and snippets.

@atika
atika / ask.sh
Last active Aug 29, 2015
This is a general-purpose function to ask Yes/No questions in Bash, either with or without a default answer.
View ask.sh
#!/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 Nov 8, 2014
Display a matrice of Bash Colors in the terminal
View bash_colors.sh
#!/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
View mbp2011fix.sh
#!/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 Aug 29, 2015
Simple content generator from a template file and variables. Replace variables on a file with bash. I use it for an html email template.
View template.sh
#!/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 Nov 10, 2014
Dropzone 3 action snippet for Sublime Text
View dropzone.sublime-snippet
<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 Dec 23, 2014
Update a GitHub Forked Repository with his Upstream/Master (and update remote master)
View git-sync-upstream.sh
#!/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 Aug 29, 2015
Self-Signed Certificate for Apache
View apache-selfsigned-cert-gen.sh
#!/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 Apr 4, 2015
Check until host is up using PING
View checkisup
# 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
Split a QuickTime video in multiple part (set cut mark in seconds)
View split_quicktime_movie.scpt
# 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 Oct 21, 2015
Alias to open a GitHub URL from a Git Repo
View github-open-url.sh
github-open-url='git remote -v | grep fetch | grep -oE '\''https://github.com/\S+'\'' | xargs -I{} open {}'