Skip to content

Instantly share code, notes, and snippets.

Avatar

Jony Santos jonyfs

View GitHub Profile
@sergiolopes
sergiolopes / Periodo.java
Created Oct 19, 2009
exemplo de classe imutável usando flyweight
View Periodo.java
import java.util.Calendar;
public final class Periodo {
private final Calendar inicio;
private final Calendar fim;
public Periodo(Calendar inicio, Calendar fim) {
this((Calendar) inicio.clone(), (Calendar) fim.clone(), false);
}
@lucascs
lucascs / Calculadora.java
Created Feb 21, 2011
Programação funcional em Java
View Calculadora.java
public class Calculadora {
private static final Prova _ = of(Prova.class);
public double mediaDeProvas(List<Prova> provas) {
return mediaPonderada(provas, function(_.getNota()), function(_.getPeso()));
}
public <T> double mediaPonderada(List<T> lista, Function<T, Double> valor, Function<T, Double> peso) {
double soma = 0.0;
double somaPesos = 0.0;
@runeflobakk
runeflobakk / EqualsAndHashCodeTemplate.java
Created Aug 23, 2011
equals() and hashCode() template for Eclipse. It uses EqualsBuilder and HashCodeBuilder in Apache Commons Lang.
View EqualsAndHashCodeTemplate.java
${e:import(org.apache.commons.lang3.builder.EqualsBuilder)}
${h:import(org.apache.commons.lang3.builder.HashCodeBuilder)}
@Override
public boolean equals(Object object) {
if (object instanceof ${enclosing_type}) {
${enclosing_type} another = (${enclosing_type}) object;
return new EqualsBuilder().append(${replaceWithFieldName}, another.${replaceWithFieldName}).isEquals();
}
@jamesmorgan
jamesmorgan / CopyFromOneServerToAnother.groovy
Created Oct 15, 2011
Copy Messages from one ActiveMQ instance to another with Apache Camel and Groovy
View CopyFromOneServerToAnother.groovy
import org.apache.activemq.camel.component.ActiveMQComponent
import org.apache.camel.CamelContext
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
class CopyFromOneServerToAnother extends RouteBuilder{
public static void main(String[] args) {
@legzo
legzo / log4jAdmin.jsp
Created Oct 17, 2011 — forked from anonymous/log4jAdmin.jsp
Change log4j log levels runtime from a jsp
View log4jAdmin.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="org.apache.log4j.Level" %>
<%@ page import="org.apache.log4j.LogManager" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.Arrays" %>
<% long beginPageLoadTime = System.currentTimeMillis();%>
@reyjrar
reyjrar / New-iTerm-Window.scpt
Created Feb 8, 2012
AppleScript to Open a New iTerm Window and bring it to the front
View New-iTerm-Window.scpt
(*
* New-iTerm-Window.scpt
*
* Intended for use with QuickSilver
* I mapped option-y to running this script to create
* a new iTerm window on the current workspace
*
* Based on much Googling - very little "original" code here
* Comments/Suggestions to brad.lhotsky@gmail.com
*)
@zuch
zuch / JSONtoXML.java
Last active Dec 25, 2020
java - Convert JSON to XML
View JSONtoXML.java
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import org.json.JSONException;//http://bit.ly/12O4D2w
@sjaakd
sjaakd / binding.xjb
Created Jan 2, 2014
OGC JAXB project to demonstrate what's needed foor custom factories in MapStruct
View binding.xjb
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:globalBindings
fixedAttributeAsConstantProperty="true"
typesafeEnumBase="xs:string"
typesafeEnumMemberName="generateName"
@ghusta
ghusta / LocalDateTimeAdapter.java
Created Jan 15, 2014
LocalDateTimeAdapter, useful to convert String to Joda Time's LocalDateTime and conversely, for use with JAXB 2.0. Can be used when customizing XML Schema to Java Representation Binding (XJC).
View LocalDateTimeAdapter.java
package xml.adapters.jodatime;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.joda.time.LocalDateTime;
/**
* LocalDateTimeAdapter, useful to convert String to Joda Time's LocalDateTime and conversely, for use with JAXB 2.0.
* <br>
* Can be used when customizing XML Schema to Java Representation Binding (XJC).
@gabrielbauman
gabrielbauman / CardType.java
Last active Apr 27, 2021
A Java enum representing credit card types (Visa, Mastercard etc) that can detect card type from a credit card number.
View CardType.java
package com.gabrielbauman.gist;
import java.util.regex.Pattern;
public enum CardType {
UNKNOWN,
VISA("^4[0-9]{12}(?:[0-9]{3}){0,2}$"),
MASTERCARD("^(?:5[1-5]|2(?!2([01]|20)|7(2[1-9]|3))[2-7])\\d{14}$"),
AMERICAN_EXPRESS("^3[47][0-9]{13}$"),