Skip to content

Instantly share code, notes, and snippets.

View Godoy's full-sized avatar

Adriano Godoy Godoy

View GitHub Profile
@Godoy
Godoy / gist:4538424
Last active June 16, 2020 17:44
Desfazendo coisas no Rails
$ rails generate controller Noticias titulo
$ rails destroy controller Noticias titulo
$ rails generate model Noticia titulo:string
$ rails destroy model Noticia
$ rake db:migrate
$ rake db:rollback
$ rake db:migrate VERSION=0 #defaz todas as migrations, deixa o banco "limpo"
@Godoy
Godoy / example.cshtml
Last active January 14, 2016 12:46
Get current action name in view #.net
@ViewContext.RouteData.GetRequiredString("action")
@Godoy
Godoy / Gemfile
Created January 15, 2013 15:31
Deploy rails application in heroku
group :production do
gem 'thin'
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
@Godoy
Godoy / contact.js.coffee
Last active December 11, 2015 03:39
Sending contact form with coffee + jquery-validate + ajax-post
$ ->
$('#formId').validate
rules: {
'message[name]': "required"
'message[email]': 'required'
'message[subject]': 'required'
'message[body]': 'required'
}
submitHandler: (form) ->
$.post(
@Godoy
Godoy / gist:4547092
Created January 16, 2013 13:20
Send email to an SMTP endpoint using STARTTLS. (from AWS Developer Guide)
public static void SendWithSMTP(string username, string password, string host, int port)
{
using (var client = new System.Net.Mail.SmtpClient(host, port))
{
client.Credentials = new System.Net.NetworkCredential(username, password);
client.EnableSsl = true;
client.Send("from@example.com", "to@example.com", "This is a test subject.", "This is a test email message body.");
}
}
@Godoy
Godoy / gist:4566507
Created January 18, 2013 17:43
Force update the content on a remote twitter bootstrap modal
$('body').on('hidden', '.modal', function () {
$(this).removeData('modal');
});
@Godoy
Godoy / gist:4588735
Created January 21, 2013 19:51
Select, separated by commas, the fields in a many-to-many relationship
SELECT DISTINCT Cadastro.id, Cadastro.nome,
STUFF(
(SELECT ', ' + Area.nome
FROM Area_Cadastro, Area
WHERE Cadastro.ID = Area_Cadastro.cadastro_id AND Area_Cadastro.area_id = Area.id
FOR XML PATH (''))
, 1, 1, '') AS areas
FROM Cadastro
@Godoy
Godoy / rails_mailer_smtp.md
Last active March 11, 2024 19:01
Config Ruby on Rails with SMTPs - dreamhost outlook

Settings for rails smtp

config/environments/development.rb

Set raise_delivery_errors true on development

  config.action_mailer.raise_delivery_errors = true 

IMPORTANT

string UserAgent = Request.UserAgent.ToString();
UserAgent = UserAgent.ToLower();
if (UserAgent.Contains("iphone") || UserAgent.Contains("symbianos") || UserAgent.Contains("ipad") || UserAgent.Contains("ipod") || UserAgent.Contains("android") || UserAgent.Contains("blackberry") || UserAgent.Contains("samsung") || UserAgent.Contains("nokia") || UserAgent.Contains("windows ce") || UserAgent.Contains("sonyericsson") || UserAgent.Contains("webos") || UserAgent.Contains("wap") || UserAgent.Contains("motor") || UserAgent.Contains("symbian"))
{
Response.Write("Go with Mobile Device!!!");
}
else
{
Response.Write("Go with normal browser!!!");
@Godoy
Godoy / gist:5032291
Last active December 14, 2015 04:59
Expressão regular em C# para pegar ID de vídeos de uma url do Youtube.
string id = string.Empty;
if (!String.IsNullOrEmpty(@Model.Video))
{
System.Text.RegularExpressions.Regex regexYoutube = new System.Text.RegularExpressions.Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
System.Text.RegularExpressions.Match youtubeMatchs = regexYoutube.Match(Model.Video);
if (youtubeMatchs.Success)
{
id = youtubeMatchs.Groups[1].Value;
}