Skip to content

Instantly share code, notes, and snippets.

View alessandroleite's full-sized avatar

Alessandro Leite alessandroleite

View GitHub Profile
@alessandroleite
alessandroleite / Objects
Created July 8, 2012 21:59
Classe Utilitária para serialização e desserialização de Objectos Java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@alessandroleite
alessandroleite / RoundRobinDatacenterBroker.java
Last active January 5, 2018 06:25
An example of DatacenterBroker that allocates the VMs following the Round-Robin algorithm.
package org.cloudbus.cloudsim.examples;
import java.util.List;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
@alessandroleite
alessandroleite / CircularHostList.java
Created November 14, 2012 14:16
An implementation of Round-Robin VmAllocationPolicy of CloudSim framework
package org.cloudbus.cloudsim.examples;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.Host;
@alessandroleite
alessandroleite / CloudSimExample9.java
Last active February 22, 2018 04:58
A CloudSim example using a VmAllocationPolicy and DatacenterBroker based in Round-Robin policy.
package org.cloudbus.cloudsim.examples;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@alessandroleite
alessandroleite / gist:4088216
Created November 16, 2012 15:31
Leituras Recomendadas de Orientação a Objetos
  1. The Art of Readable Code - http://www.amazon.com/The-Readable-Code-Dustin Boswell/dp/0596802293/ ; Edição em Português - A Arte de Escrever Programas Legíveis - (Capítulo de Exemplo: http://goo.gl/cQSTr, sumário: http://goo.gl/o1FBD).

  2. Growing Object-Oriented Software, Guided by Tests - http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627/ - Um ótimo livro para aprender corretamente Orientação a Objetos juntamente com a prática de testes. Este livro mais o do Meilir Pages-Jones (título abaixo, 3) são leituras obrigatórias para todo desenvolvedor O.O. Por exemplo, muitos livros e cursos de O.O só retratam como características do paradigma, encapsulamento, polimorfismo, herança e abstração e esquecem de mencionar outras, também importantes, como covariância;

  3. Fundamentals of Object-Oriented Design in UML - http://www.amazon.com/Fundamentals-Object-Oriented-Design-Meilir-Page-Jones/dp/020169946X/

  4. Clean Code: A Handbook of Agile Software Craftsmanship - http://www.amazon

@alessandroleite
alessandroleite / gist:4233584
Created December 7, 2012 14:28
Counting the CPU cycles of a function/procedure
/////////////////////////////////////////////////////////////////////////
static u_int64_t start = 0;
void access_counter(unsigned* hi, unsigned* low);
void start_counter()
{
unsigned hi, lo;
access_counter(&hi, &lo);
start = ((u_int64_t)hi << 32) | lo;
@alessandroleite
alessandroleite / RoundRobinVmAllocationPolicy.java
Created January 22, 2013 20:20
Round-Robin {@link Vm} allocation policy for CloudSim
package org.cloudbus.cloudsim.examples;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
@alessandroleite
alessandroleite / Hosts.java
Created January 22, 2013 20:24
Hosts.java
package org.cloudbus.cloudsim.examples;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.Host;
@alessandroleite
alessandroleite / MQCommunicator.java
Created February 17, 2013 13:56
this class provides access to the MQSeries queue facilities. Once instantiated, the main application program need only call the 'send' and 'receive' methods to put & get strings. The send method returns an MQMessage object the handle of which is used to retrieve the reply
/* This class provides access to the MQSeries queue facilities. Once
instantiated, the main application program need only call the 'send' and
'receive' methods to put & get strings. The send method returns an MQMessage
object the handle of which is used to retrieve the reply. */
import java.io.*;
import com.ibm.mq.*; // Include the MQ package
public class MQCommunicator {
private String hostname; // Define the name of your host to connect to
@alessandroleite
alessandroleite / Husband.java
Created March 6, 2013 14:06
Example of Observer Pattern with AspectJ
package example.types;
import java.util.Arrays;
import example.pattern.Observer;
import example.pattern.Subject;
public class Husband extends Person implements Observer {
private Person wife;