Skip to content

Instantly share code, notes, and snippets.

View fernyb's full-sized avatar

Fernando Barajas fernyb

View GitHub Profile
@fernyb
fernyb / gist:5174248
Created March 16, 2013 00:19
redirect port
--iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
--iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
--iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
### Nginx upstart script
### source: http://serverfault.com/a/391737/70451
### /etc/init/nginx.conf
description "nginx http daemon"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
@fernyb
fernyb / gist:5638459
Created May 23, 2013 18:46
Clear DNS Cache on Mac OSX
dscacheutil -flushcache
@fernyb
fernyb / email_validator.rb
Last active December 17, 2015 20:19
Validator Email Address Validator
#validates :email, :presence => true, :email => true
require 'mail'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain and that value is an email address
r = m.domain && m.address == value
t = m.__send__(:tree)
@fernyb
fernyb / gist:5922306
Created July 3, 2013 20:04
Parse JSON in Rails
@response = ActiveSupport::JSON.decode(@data.body)
@fernyb
fernyb / gist:5953514
Created July 8, 2013 23:56
Get file mime type using command line
# Get file mime type using command line
file --mime-type -b Transcodez-license.transcodez
@fernyb
fernyb / gist:6371782
Created August 28, 2013 21:50
Remove lots of files from git
git rm $(git ls-files --deleted)
@fernyb
fernyb / gist:7130154
Last active December 26, 2015 09:29
Reset Postgres Counter
skatr_development=# \d spots
Table "public.spots"
Column | Type | Modifiers
-------------+-----------------------------+----------------------------------------------------
id | integer | not null default nextval('spots_id_seq'::regclass)
ALTER SEQUENCE spots_id_seq RESTART WITH 1;
@fernyb
fernyb / gist:7745388
Created December 2, 2013 05:10
Burn DVD from command line - Ubuntu
fernyb@fernyb-SD30V10:~/sources$ wodim --devices
wodim: Overview of accessible drives (1 found) :
-------------------------------------------------------------------------
0 dev='/dev/sg0' rwrw-- : 'TSSTcorp' 'CDDVDW SH-S203B'
-------------------------------------------------------------------------
wodim dev=/dev/sg0 -v -data ~/the-dictator.iso
@fernyb
fernyb / gist:7751198
Created December 2, 2013 15:31
Make DVD disc image
# Current path should have VIDEO_TS directory
#
mkisofs -dvd-video -o ~/Desktop/back-to-the-future.iso .