Skip to content

Instantly share code, notes, and snippets.

View souzaonofre's full-sized avatar

Onofre Souza souzaonofre

View GitHub Profile
#!/bin/bash
#
url="$1"; [ ${url} == "" ] && exit 1;
#
[[ "$(echo ${url} | egrep '^http[s]?\:\/\/\w+(\.\w+)?(\.\w+)?')" == "" ]] && exit 1;
#
bad_list='(http|www|org|com|edu|in|io|can|like|to|in|of|de|em|para)';
#
name_list=$(echo ${url} | \
sed -r "s/^http[s]?\:\/\///" | \
def make_slug(str)
return if str.blank? or !str.instance_of? String
s = str
s.downcase!
s.strip!
s.gsub!(/[^a-z0-9\s-]/, '') # Remove non-word characters
s.gsub!(/\s+/, '-') # Convert whitespaces to dashes
s.gsub!(/-\z/, '') # Remove trailing dashes
s.gsub!(/-+/, '-') # get rid of double-dashes
s.to_s
respond_to do |format|
format.json { render json: @model_instance, :only => [:id, :name] }
end