Skip to content

Instantly share code, notes, and snippets.

View matheustardivo's full-sized avatar

Matheus Tardivo matheustardivo

View GitHub Profile
<% if @url.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@url.errors.count, "error") %> prohibited this url from being saved:</h2>
<ul>
<% @url.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
@matheustardivo
matheustardivo / chat.html
Created April 9, 2012 13:11
Simple Chat app using Node.js and Redis
<!DOCTYPE html>
<html>
<head>
<title>Node.js chat</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="/nowjs/now.js"></script>
<script type="text/javascript">
$(document).ready(function() {
now.receiveMessage = function(time, name, message) {
@matheustardivo
matheustardivo / gist:2376326
Created April 13, 2012 11:54
JAXB Marshaller snippet
JAXBContext jaxbContext = JAXBContext.newInstance(Profile.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(profile, System.out);
@matheustardivo
matheustardivo / validador_cpf.rb
Created April 26, 2012 13:08
Validador de CPF
class ValidadorCPF
REGEX = /\A(\d{3}\.?){2}\d{3}\-?\d{2}\Z/
def self.valido?(cpf)
return false unless REGEX =~ cpf
arr = cpf.scan(/\d/).take(9)
arr << calcular_dv(arr)
@matheustardivo
matheustardivo / HelloYouPortlet.java
Created October 23, 2012 13:22
Exemplo de portlet do Liferay *SUPER* simples ;)
package com.liferayinaction.portlet;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
@matheustardivo
matheustardivo / correios.xml
Created October 29, 2012 12:59
Exemplo de resposta do tracking dos Correios.
<?xml version="1.0" encoding="iso-8859-1" ?>
<sroxml>
<versao>1.0</versao>
<qtd>1</qtd>
<TipoPesquisa>Lista de Objetos</TipoPesquisa>
<TipoResultado>Todos os eventos</TipoResultado>
<objeto>
<numero>SW371675211BR</numero>
<evento>
<tipo>BDE</tipo>
@matheustardivo
matheustardivo / CorreiosCarrierTracker.java
Created October 29, 2012 13:00
Exemplo de código para fazer o tracking do site dos Correios.
import java.io.DataInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLConnection;
public class CorreiosCarrierTracker {
public static void main(String[] args) {
@matheustardivo
matheustardivo / DatabaseIntegration.java
Created December 18, 2012 17:28
Testing with dbunit
package com.walmart.customer.services.frontend.domain.test;
import java.sql.Connection;
import javax.sql.DataSource;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
@matheustardivo
matheustardivo / App.java
Created April 14, 2013 20:07
Prosdac report spreadsheet reader
package net.tardivo.prosoft.excel.reader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@matheustardivo
matheustardivo / lexicographic_paths.rb
Last active January 15, 2016 15:10
Lexicographic paths
# Ruby version from https://github.com/derekhh/HackerRank/blob/master/mathematics/combinatorics/lexicographic-steps.cpp
# Build the 'Lower Pascal matrix'
# http://rosettacode.org/wiki/Pascal_matrix_generation#Ruby
ng = (g = 0..20).collect{ [] }
g.each { |i| g.each { |j| ng[i][j] = j == 0 ? 1 : i < j ? 0 : ng[i - 1][j - 1] + ng[i - 1][j] } }
# Uncomment the line bellow to print the matrix
# ng.each { |i| i.each { |j| print "#{j}\t" }; puts }
t = gets.chomp.to_i