Skip to content

Instantly share code, notes, and snippets.

View juanvgarcia's full-sized avatar

Juan García juanvgarcia

View GitHub Profile
@juanvgarcia
juanvgarcia / change_hosts.sh
Created October 30, 2013 06:14
This a very simple script that will comment host names depending on their initial numbering. My home network setup is different than my home's, and therefore I use this script to change the hostnames I use for development testing purposes.
#!/bin/sh
if [ "$1" != "work" ] && [ "$1" != "home" ];
then
echo "Wrong arguments Usage: $0 home|work"
exit 65
fi
work_test_regex="^10"
home_test_regex="^192"
@juanvgarcia
juanvgarcia / change_interfaces.sh
Created November 13, 2013 03:54
Script I use to change the static network configuration for a VM (I have different network configs for home/work). This script will expect comments of the form #work config start or #home config start to mark each configuration section. I complement it with two alias that include sudo on ~/.bash_profile.
#!/bin/sh
if [ "$1" != "work" ] && [ "$1" != "home" ];
then
echo "Wrong arguments Usage: $0 home|work"
exit $E_BADARGS
fi
interface_file='/etc/network/interfaces'
work_config_start=`grep -n "#work config start" $interface_file | awk -F':' '{print $1}'`
@juanvgarcia
juanvgarcia / PhoneNumberEditor.js
Last active January 2, 2016 01:39
This code will add a "PhoneNumber" custom editor for Backbone Forms. The formatting function was taken from: https://github.com/groupme/jquery-format-phone/blob/master/src/format_phone_input.js, and you could replace it as needed.
Backbone.Form.editors.PhoneNumber = Backbone.Form.editors.Text.extend({
initialize: function(options) {
Backbone.Form.editors.Text.prototype.initialize.call(this, options);
this.$el.on('keyup', function(e){
var input = $(e.currentTarget);
input.val(input.val().replace(/[^\d]/g, ''));
var digits = input.val();
if (e.which == 8 && digits.length <= 3) {
return;
@juanvgarcia
juanvgarcia / Polyglot JS Snippet
Created March 3, 2014 15:46
Snippet so we don't go crazy adding polyglot.t everywhere
<snippet>
<content><![CDATA[polyglot.t('$1')]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>ps</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<!-- Optional: Description to show in the menu -->
<description>Polyglot JS</description>
</snippet>
@juanvgarcia
juanvgarcia / Polyglot HTML Gist
Created March 3, 2014 15:49
Snippet so we don't go crazy adding the polyglot <%t %> everywhere! Provided by @lustercr
<snippet>
<content><![CDATA[<%t '$1' %>]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>ts</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<!-- Optional: Description to show in the menu -->
<description>Polyglot HTML</description>
</snippet>
@juanvgarcia
juanvgarcia / require js snippet
Created March 5, 2014 15:58
Snippet for require function calls
<snippet>
<content><![CDATA[require('$1')]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>req</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<!-- Optional: Description to show in the menu -->
<description>Require JS</description>
</snippet>
@juanvgarcia
juanvgarcia / install_ruby.sh
Created April 23, 2014 05:20
Shell script to install Ruby from a newly installed Vagrant VM.
#!/bin/sh
sudo apt-get update
sudo apt-get install curl
curl -L get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvm install ruby 2.1.0