Skip to content

Instantly share code, notes, and snippets.

View mrinalwadhwa's full-sized avatar
🦀

Mrinal Wadhwa mrinalwadhwa

🦀
View GitHub Profile
@mrinalwadhwa
mrinalwadhwa / download.sh
Created February 13, 2016 14:01
Script to download and check hash
#!/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 February 13, 2016 13:43
Vagrantfile with cachier
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 February 12, 2016 11:00
Pad a binary with zeros
-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.
#!/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 ]]
}
#!/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
#!/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)
@mrinalwadhwa
mrinalwadhwa / make_osx_vagrant_box.sh
Created June 19, 2013 18:47
Create an OSX Vagrant Box
# 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 June 20, 2012 04:00
SCSS custom function to insert data uri into style sheets.
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 June 19, 2012 01:34
convert to data uri
# 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
@mrinalwadhwa
mrinalwadhwa / index.html
Created June 15, 2012 20:32
CSS to make a div take the entire page, width & height 100%
<!DOCTYPE html>
<!--[if lt IE 7]><html class="lt-ie9 lt-ie8 lt-ie7" lang="en"><![endif]-->
<!--[if IE 7]><html class="lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if IE 8]><html class="lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Box</title>
<style>