Skip to content

Instantly share code, notes, and snippets.

View kidchenko's full-sized avatar

Jose Barbosa kidchenko

View GitHub Profile
@kidchenko
kidchenko / ajax
Last active December 23, 2015 02:09
Exemplo de uma chamada ajax sem seletores de elementos entre as funlçoes ajax.
function Tour(el) {
var tour = this;
this.el = el;
this.fetchPhotos = function() {
$.ajax('/photos.html', {
data: {location: tour.el.data('location')},
context: tour,
success: function(response) {
this.el.find('.photos').html(response).fadeIn();
},
@kidchenko
kidchenko / callback_p
Created September 14, 2013 20:03
Maneira simples e elegante de montar mensagens de respostas para callback usando $.append
success: function(response) {
$('.tour').html('<p></p>') //cria um elmento p em .tour
.find('p') //busca o elemento p recem criado
.append('Trip to ' + response.description) //monta a mensagem
.append(' at $' + response.price)
.append(' for ' + response.nights + ' nights')
.append('. Confirmation: ' + response.confirmation);
}
//OU
@kidchenko
kidchenko / $.detach()
Last active December 23, 2015 02:19
A função $.detach() remove os elementos do dom preservando todos os dados e eventos.
//.detach() removes the list from the DOM, then it can be modified and reinserted into the status element.
//.detach() removes an element from the DOM, preserving all data and events.
This is useful to minimize DOM insertions with multiple html elements.
$('.update-available-flights').on('click', function() {
$.getJSON('/flights/late', function(result) {
var flightElements = $.map(result, function(flightItem, index){
var flightEl = $('<li>'+flightItem.flightNumber+'-'+flightItem.time+'</li>');
return flightEl;
});
$('.flight-times').detach()
@kidchenko
kidchenko / list_comprehension_sintaxe.py
Created September 17, 2013 23:49
List Comprehension Sintaxe.
new_list = [x for x in range(1,6)]
# => [1, 2, 3, 4, 5]
doubles = [x*2 for x in range(1,6)]
# => [2, 4, 6, 8, 10]
doubles_by_3 = [x*2 for x in range(1,6) if (x*2)%3 == 0]
# => [6]
@kidchenko
kidchenko / linq_sub_entidade.cs
Created October 22, 2013 18:18
Linq para retornar apenas um sub-entidade sem obter a entidade por completa.
var juca = target.SelectMany(x => x.Entidade)
.SingleOrDefault(y => y.SubEntidade.Equals(argumento));
@kidchenko
kidchenko / _vimrc
Created October 28, 2013 15:35
File _vimrc for VIM
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
@kidchenko
kidchenko / 0_reuse_code.js
Created November 5, 2013 15:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kidchenko
kidchenko / plugin-bootstrap
Created November 12, 2013 16:21
Plugins Bootstrap
http://speckyboy.com/2013/05/01/bootstrap-toolbox/
http://pinesframework.org/pnotify/#demos-simple
http://alittlecode.com/files/jQuery-Validate-Demo/index.html
http://gregfranko.com/jquery.tocify.js/#Donation
http://tableclothjs.com/
http://billpull.github.io/knockout-bootstrap/
@kidchenko
kidchenko / Global.asax.cs
Last active September 1, 2020 04:03
Configuration Unity Container with ASP NET Web API
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
// *** Other Configurations ***
UnityConfiguration(GlobalConfiguration.Configuration);
}
public void UnityConfiguration(HttpConfiguration httpConfiguration)
@kidchenko
kidchenko / Global.asax.cs
Created November 18, 2013 17:26
Configuration Unity Container with ASP NET MVC
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
// *** Other Configurations ***
UnityConfiguration();
}
public void UnityConfiguration()
{