Skip to content

Instantly share code, notes, and snippets.

View sanjayginde's full-sized avatar

Sanjay Ginde sanjayginde

View GitHub Profile
@sanjayginde
sanjayginde / deploy.sh
Created September 4, 2019 23:18
Ansible deploy via docker
#!/bin/bash -e
if [ -z "$KEY_DIR" ]; then
echo "FAILED: \$KEY_DIR is required. Please point it at the location of your identity keys."
exit 1
fi
# if [ -z "$AWS_ACCESS_KEY_ID" ]; then
# echo "FAILED: \$AWS_ACCESS_KEY_ID is required. Please pass this variable inline or export to your session."
# exit 1
@sanjayginde
sanjayginde / pjax.html.haml
Last active October 25, 2017 14:23
PJAX concern
%title=h ((title=yield(:title)).blank?) ? "Contently" : "#{title} : Contently".html_safe
=yield
=yield :javascript
@sanjayginde
sanjayginde / apache-headers.php
Created July 8, 2016 19:53
Snippet to output headers in PHP
<?php
echo "Raw dump of Apache Headers follows.<br/>";
foreach (getallheaders() as $name => $value) {
echo "$name: $value<br/>";
};
echo '<hr/>$_SERVER dump: <pre>';
print_r($_SERVER);
echo '</pre>';
?>
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
function base64_decode(input){
var output = new Array();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
var orig_input = input;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
if (orig_input != input)

Keybase proof

I hereby claim:

  • I am sanjayginde on github.
  • I am sanjayginde (https://keybase.io/sanjayginde) on keybase.
  • I have a public key whose fingerprint is 20C7 5D65 4559 F7B2 26F7 173E 2C75 9150 3F79 4AF9

To claim this, I am signing this object:

@sanjayginde
sanjayginde / read-more.css.sass
Created February 20, 2014 19:44
Read more/less
.expandable
.read-more, .read-less
// link styles go here (if needed)...
.long-content
display: none
@sanjayginde
sanjayginde / empty.html.haml
Last active December 18, 2015 14:49
Example to 'disable' layouts in a Rails controller test. Uses an 'empty' layout, which can allow for testing that the the title tag and javascript is properly added...
-# Empty layout used as layout replacement for testing...
!!! 5
!= html5_haml_tag(:lang => 'en') do
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
%title=h ((title=yield(:title)).blank?) ? "Contently" : "#{title} : Contently".html_safe
%body
=yield
=yield :javascript
=yield :jstemplates
@sanjayginde
sanjayginde / jquery.rails.async-confirm-dialog.js
Last active December 13, 2015 17:38
Implementation of custom, async confirmation dialog with Rails UJS
;(function($, document) {
$(document).delegate('a[data-confirm]', 'confirm', function(event) {
event.preventDefault();
var $link = $(this);
// Placeholder for custom confirmation popup, etc
my_custom_dialog_widget.confirm({
message: $link.attr('data-confirm'),
title: "Are you sure?",
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@sanjayginde
sanjayginde / file_size_validation.jqtools.js
Last active December 11, 2015 17:29
JavaScript file size validation for HTML 5, using jQuery Tools validation and Parsley validation. (Additionally, extended modernizer for HTML5 File API.). The 'data-filemaxsize' attribute should be set in megabytes.
/**
* File size validation using jQuery Tools Validation (http://jquerytools.org/documentation/validator/index.html)
*/
if (Modernizr.fileapi) {
$.tools.validator.fn('input[type="file"][data-filemaxsize]', function($file_input, value) {
var files = $file_input.get(0).files,
max_megabytes = parseInt($file_input.data('filemaxsize')),
max_bytes = max_megabytes * BYTES_PER_MEGABYTE;
if (files.length > 0 && files[0].size > max_bytes) {