Skip to content

Instantly share code, notes, and snippets.

View Godoy's full-sized avatar

Adriano Godoy Godoy

View GitHub Profile
@Godoy
Godoy / gist:5051218
Last active December 14, 2015 07:29
Paginação simples com números - wordpress
<div class="clearfix">
<nav class="wp-pagenavi">
<?php
global $wp_query;
$big = 999999876; //necessario numero inteiro foda
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
@Godoy
Godoy / gist:5110936
Last active December 14, 2015 15:49 — forked from tiagobbraga/gist:5110874
Observando alterações de DOM em uma div
setTimeout
(
StartWatching,
100
);
function StartWatching()
{
$("#someDiv").bind('DOMSubtreeModified',function() {
alert('modificou');
@Godoy
Godoy / api_controller.rb
Created March 10, 2013 13:37
Devise - Autenticação por Token como parâmetro no Header
class Api::ApiController < ActionController::Base
prepend_before_filter :get_auth_token
respond_to :json
public
def restrict_access
api_key = User.find_by_authentication_token(params[:auth_token])
head :unauthorized unless api_key
end
@Godoy
Godoy / gist:5137345
Last active December 14, 2015 19:29 — forked from leandrocustodio/gist:5137295
Carregar Json de uma URL externa (facebook, twitter...)
string recebeJSON = "";
using (var client = new WebClient())
{
recebeJSON = client.DownloadString("URL do JSON");
}
//transforma a string em objeto
JObject _recebeJSON = JObject.Parse(recebeJSON);
@Godoy
Godoy / gist:5256851
Last active December 15, 2015 11:59
Pegar a URL absoluta de uma aplicação .NET C#
string UrlAplicacao = Request.Url.Scheme+"://"+Request.Url.Authority + Request.ApplicationPath;
@Godoy
Godoy / MeuController.cs
Last active December 15, 2015 20:49
Obter access_token do facebook após o callback de login usando a lib Facebook C# SDK (https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/)
using Facebook;
....
public ActionResult actionCallback()
{
try
{
if (String.IsNullOrEmpty(Request["code"]))
throw new Exception("Não foi possível efetuar login na aplicação.");
@Godoy
Godoy / application.rb
Created April 16, 2013 12:56
Enviando e-mail com Action Mailer em Rails.
config.action_mailer.smtp_settings = {
:address => "mail.adrianogodoy.com",
:port => 587,
:domain => "adrianogodoy.com",
:user_name => "sender@adrianogodoy.com",
:password => "senha",
:authentication => :login,
:enable_starttls_auto => false
}
config.action_mailer.raise_delivery_errors = true
@Godoy
Godoy / gist:6155683
Created August 5, 2013 12:49
busca de parte do valor por regex em um IEnumerable
.Where(u => Regex.IsMatch(u.Nome, busca, RegexOptions.IgnoreCase))
@Godoy
Godoy / gist:6234925
Created August 14, 2013 19:55
Correção de posicionamento do gráfico para o plugin de Wordpress Iced Visualization Charts
<?php
function iced_chart_display($atts, $content = null)
{
global $chart_id;
wp_enqueue_script('google-visualization', 'http://www.google.com/jsapi', array('jquery'), '1.0', true);
wp_enqueue_script('iced-visualization', plugins_url('iced-visualization.js', __FILE__), array('google-visualization'), '1.0', true);
$type = $atts['type'];
@Godoy
Godoy / gist:6311383
Created August 22, 2013 19:04
cabeçalhos para gerar excel (xls) no .net C#
HttpContext.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Response.AddHeader("content-disposition", "attachment;filename=nome_arquivo-" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm") + ".xls");
// HttpContext.Response.Charset = "utf-8";
HttpContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");