Skip to content

Instantly share code, notes, and snippets.

@buoyant
buoyant / gist:cd7213695ca4d7288e36
Created October 7, 2015 09:43 — forked from Hammadk/gist:0a196dd1ac5ad971df1a
git pre-push hook: get warned before pushing to git master branch
#!/bin/bash
# Warn before pushing to protected branches
# Make script executable with chmod +x pre-push
# Bypass with git push --no-verify
BRANCH=`git rev-parse --abbrev-ref HEAD`
PROTECTED_BRANCHES="^(master|dev|release-*|patch-*)"
if [[ "$BRANCH" =~ $PROTECTED_BRANCHES ]]; then
read -p "Are you sure you want to push to \"$BRANCH\" ? (y/n): " -n 1 -r < /dev/tty
@buoyant
buoyant / mysql2win
Last active August 29, 2015 14:08
Rails Installer Mysql2 Windows Fix
gem install mysql2 -- '--with-mysql-lib="c:\Program Files (x86)\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files (x86)\MySQL\MySQL Server 5.6\include"'
# for specific version
gem install mysql2 -v=0.3.14 -- '--with-mysql-lib="c:\Program Files (x86)\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files (x86)\MySQL\MySQL Server 5.6\include"'
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#regform_district_id').html("<option value=''>Select District</option>");
});
</script>
post "dynamic_districts/:id" => "regforms#dynamic_districts"
$('#regform_district_id').empty();
<% for district in @districts %>
$('#regform_district_id').append($("<option></option>").attr("value",<%= district.id %>).text('<%= district.name %>'));
<% end %>
@buoyant
buoyant / application.js
Created December 3, 2012 17:07
exists in public/javascripts folder
jQuery(document).ready(function() {
jQuery('#regform_state_id').change(function() {
var data=$('#regform_state_id').val();
$.ajax({
type: "POST",
url: "http://"+location.host+"dynamic_districts/"+data,
data: data,
});
});
});
@buoyant
buoyant / regform.rb
Created December 3, 2012 17:02
model regform.rb
belongs_to :state
belongs_to :district
@buoyant
buoyant / regforms_controller.rb
Created December 3, 2012 16:57
controller file of registration form
def dynamic_districts
@districts = District.find_all_by_state_id(params[:id])
respond_to do |format|
format.js
end
end