Skip to content

Instantly share code, notes, and snippets.

Avatar

Mrinal Wadhwa mrinalwadhwa

View GitHub Profile
View prompt.sh
function prompt_color(){
case $# in
3) echo -en "\[\033[$2\]\[\033[$3\]\[$1\033[0m\]";;
2) echo -en "\[\033[$2\]$1\[\033[0m\]";;
1) echo -en "$1";;
*) echo -en "";;
esac
}
function git_branch(){
@mrinalwadhwa
mrinalwadhwa / download.sh
Created Feb 13, 2016
Script to download and check hash
View download.sh
#!/usr/bin/env bash
#
# Usage:
# download.sh URL DEST MD5
#
# Example:
# download.sh \
# http://a.mbbsindia.com/hbase/1.1.3/hbase-1.1.3-bin.tar.gz \
# /var/downloads/cache/1c9f52d89cf665ef35f101cb8f2b57e4 \
# 1c9f52d89cf665ef35f101cb8f2b57e4
@mrinalwadhwa
mrinalwadhwa / Vagrantfile
Created Feb 13, 2016
Vagrantfile with cachier
View Vagrantfile
def configure_caching(config)
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
config.cache.enable :generic, { :cache_dir => "/var/downloads/cache" }
end
end
Vagrant.configure('2') do |config|
@mrinalwadhwa
mrinalwadhwa / pad_binary.erl
Last active Feb 12, 2016
Pad a binary with zeros
View pad_binary.erl
-module(pad_binary).
% http://erlang.org/pipermail/erlang-questions/2008-December/040709.html
-spec pad_binary_to(WidthInBytes :: pos_integer(), Raw :: binary()) ->
Padded :: binary().
pad_binary_to(WidthInBytes, Raw) ->
case (WidthInBytes - size(Raw) rem WidthInBytes) rem WidthInBytes of
0 -> Raw;
N -> <<Raw/binary, 0:(N*8)>>
end.
View install_xcode_cli_tools.sh
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
is_xcode_cli_tools_installed() {
xcode-select -p >/dev/null 2>&1
[[ $? -eq 0 ]]
}
View BashStrict.sh
#!/usr/bin/env bash
# redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
# `set` is safer than relying on a hashbang like `#!/bin/bash -e`
# because that is neutralized when someone runs the script as `bash script.sh`
# Exit on error. Append `|| true` if we expect an error.
# set -o errexit
View ansible-vagrant-inventory.py
#!/usr/bin/env python
import argparse
import json
import re
import subprocess
import sys
def ssh_config_lookup(key, config_text):
return re.search("(({})\s+(.*))".format(key), config_text).group(3)
View make_osx_vagrant_box.sh
# Create an OSX Vagrant Box
# Run this script from the directory that has InstallESD.dmg in it
# Get InstallESD.dmg using the method described on this link
# http://hints.macworld.com/article.php?story=20110831105634716
# Setup a vagrant box
# http://garylarizza.com/blog/2013/01/20/using-veewee-to-build-os-x-vms/
git clone git://github.com/jedi4ever/veewee.git
@mrinalwadhwa
mrinalwadhwa / data_url.rb
Created Jun 20, 2012
SCSS custom function to insert data uri into style sheets.
View data_url.rb
require 'base64'
# tools.ietf.org/html/rfc2397
# developer.mozilla.org/en/data_URIs
# "data:" + MIME type + ";base64," + base64-encoded content
def to_data_url(content, content_type)
outuri = 'data:' + content_type + ';base64'
content = Base64.encode64(content).gsub("\n", '')
outuri += ",#{content}"
@mrinalwadhwa
mrinalwadhwa / to_datauri.rb
Created Jun 19, 2012
convert to data uri
View to_datauri.rb
# tools.ietf.org/html/rfc2397
# developer.mozilla.org/en/data_URIs
require 'base64'
require 'cgi'
# based on segment7.net/projects/ruby/datafy
def to_datauri(content, content_type)
outuri = 'data:' + content_type
unless content_type =~ /^text/i # base64 encode if not text
You can’t perform that action at this time.