Skip to content

Instantly share code, notes, and snippets.

View roooodcastro's full-sized avatar

Rodrigo Castro roooodcastro

View GitHub Profile
@roooodcastro
roooodcastro / ClienteTCP.java
Created April 20, 2013 23:33
Configuração ClienteTCP
public static int PORTA_CLIENTE_TCP = 1050;
public void iniciarServidorTCP() {
fabrica = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newCachedThreadPool());
bootstrap = new ServerBootstrap(fabrica);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
@roooodcastro
roooodcastro / GraphPanel.java
Last active May 24, 2024 15:40
A simple Swing component to draw a Graph over a regular JPanel. Features a grid, customizable amount of hatch marks, axis labels,checking for minimum and maximum value to label correctly the Y-axis and customizable padding and label padding. Based on "Hovercraft Full Of Eels"'s answer on StackOverflow (http://stackoverflow.com/questions/8693342/…
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.util.ArrayList;
@roooodcastro
roooodcastro / Fileswap Batch Downloader
Created November 23, 2013 13:00
Fileswap script to download files in batch. This javascript code will iterate over an URL list to download each file in it, with an interval of 15 seconds between each link (I consider this a safe interval, as a smaller one might open too many pages at the same time, and eventually the browser won't be able to respond to the new requests, breaki…
// Example url list
list = [
"http://www.fileswap.com/dl/4VwkwcWNM/",
"http://www.fileswap.com/dl/SFIXwosILI/",
"http://www.fileswap.com/dl/KRatrq4R/",
"http://www.fileswap.com/dl/j5FxFWGTwi/",
"http://www.fileswap.com/dl/jbBYBjHOOk/",
]
download = function(url) {
@roooodcastro
roooodcastro / bdp-locales-frenzy
Created November 7, 2014 13:55
Bootstrap Datepicker gem requesting ALL locales
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.ar.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.az.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.bg.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.ca.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.cs.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.cy.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.da.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.de.js?body=1" for 127.0.0.1 at 2014-11-07 11:48:18 -0200
@roooodcastro
roooodcastro / ruby-awesome-constants-reflection.rb
Last active August 29, 2015 14:16
Criação de método baseado em constantes usando Reflection
class ControleEnade < ActiveRecord::Base
ANO_CORRENTE_ENADE_COD = 1
SEMESTRE_CORRENTE_ENADE_COD = 2
INICIO_INSCRICAO = 5
FIM_INSCRICAO = 6
INICIO_JUSTIFICATIVA = 7
FIM_JUSTIFICATIVA = 8
MSG_INSCRITO = 13
MSG_JUSTIFICATIVA = 14
@roooodcastro
roooodcastro / regex-refactoring.rb
Last active August 29, 2015 14:26
Common Regex refactoring helpers
# Use these with the 'Ctrl+R' IDE function.
# Convert hash rockets to new syntax:
/:([\w_]+) => / => /$1: /
# Convert double-quoted strings to single-quoted strings (avoid ones that can't be converted)
/"([^\n'#{}"]*)"/ => /'$1'/
@roooodcastro
roooodcastro / prawn-dynamic-repeater-content-indexing.md
Last active March 8, 2016 23:32
Rails Prawn: How to print different data per page inside a dynamic repeater

The problem with repeaters

How does Prawn's repeaters work?

Prawn is an amazingly configurable and flexible tool for PDF generation. It allows you to create boring financial style PDFs that can almost mimic a (static) Excel spreadsheet, and can also create a convincing party invitation letter.

One of Prawn's many tools to allow this kind of flexibility is the Repeater. It allows you to define a section of your PDF, and reuse it over and over, essentially stamping it on every page (or just on odd pages, or on the first 10 pages, etc, you can also configure that).

Let's create a simple PDF document as an example:

@roooodcastro
roooodcastro / aluno.rb
Last active April 15, 2016 19:38
Proposed Rails Presenter Strategy
require 'presenters/aluno_presenter'
class Aluno < ActiveRecord::Base
include Presenters::AlunoPresenter
def save
# ...
end
end
@roooodcastro
roooodcastro / insertion_sort.c
Created June 2, 2016 23:47
Trabalho 2 APA - Rodrigo Castro Azevedo
#include "sort.h"
void insertionSort(int *vector, int vectorSize) {
int currentNumber, prevNumber, index, subIndex;
// Para cada índice, posicioná-lo corretamente
for (index = 1; index < vectorSize; index++) {
subIndex = index;
currentNumber = vector[subIndex];
prevNumber = vector[subIndex - 1];
@roooodcastro
roooodcastro / arvore.txt
Created July 5, 2016 14:26
Árvore derivação exemplo 1 CUP
Sentença analizada corretamente. Sem erro.
└── PROG
├── MAIN
│ ├── class
│ ├── Factorial
│ ├── {
│ ├── public
│ ├── static
│ ├── void
│ ├── main