Skip to content

Instantly share code, notes, and snippets.

View roberto-filho's full-sized avatar

Roberto Welzel Filho roberto-filho

View GitHub Profile
@roberto-filho
roberto-filho / MapToList.java
Created April 20, 2015 14:25
Map to List with Guava
// Cria um map
Map<String, String> m = Maps.newHashMap();
// Aplica uma função ao entrySet() do map que transforma cada entry em um BasicNameValuePair
Iterable<BasicNameValuePair> transformed = Iterables.transform(m.entrySet(), new Function<Entry<String, String>, BasicNameValuePair>() {
public BasicNameValuePair apply(Entry<String,String> input) {
return new BasicNameValuePair(input.getKey(), input.getValue());
};
});
// Cria uma lista de NameValuePair
List<BasicNameValuePair> list = newArrayList(transformed);
// Remove tudo que não for dígito ou /
"ab1s/3hae/2s1h".replace(/[^\/|\d+]/g, "")
// Matches a date pattern
"01/02/2014".match(/^(\d{1,2}\/){2}(\d{2}){1,2}$/g) // true
@roberto-filho
roberto-filho / p2-deploy.sh
Created January 22, 2015 11:44
create p2 repository
if [ -z $ECLIPSE_HOME ]; then
ECLIPSE_HOME=$1
fi
HOME=$(pwd)
#echo $HOME/libs-compiled
java -jar $ECLIPSE_HOME/plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:$HOME/libs-compiled -artifactRepository file:$HOME/libs-compiled -source $HOME/libs -configs gtk.linux.x86 -compress -publishArtifacts
public static ComboBoxViewerCellEditor criarColumnComboBox(TableViewerColumn tvc, final Class<?> clazz, final String property, Object[] values, String titulo) {
return criarColunaComboBoxEditable(tvc, clazz, property, values, titulo, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (clazz.isInstance(element)) {
return element.toString();
} else {
Object value = ReflectionHelper.getValue(element, property);
return value == null ? StringUtils.EMPTY : value.toString();
}
@roberto-filho
roberto-filho / ConstructorQuerySnippet.java
Last active August 29, 2015 14:08
Usa o construtor de uma classe para retornar uma lista de resultados.
StringBuilder sb = new StringBuilder();
sb.append("SELECT new ").append(SaldoContaParteB.class.getName()).append("(sum(a.valor), conta) ");
sb.append("FROM ContaLalurParteB conta ");
sb.append("LEFT JOIN AjusteLalurParteB ajuste on ajuste.conta = conta AND ajuste.data < :dataInicio ");
sb.append("WHERE conta.empresa = :empresa");
TypedQuery<SaldoContaParteB> query = getEntityManager().createQuery(sb.toString(), SaldoContaParteB.class);
query.setParameter("empresa", empresa);
query.setParameter("dataInicial", dataInicio);
@roberto-filho
roberto-filho / subir-integracao-trackr.sh
Last active August 29, 2015 14:08
Script com os comandos para subir os serviços do trackr e da integração.
#!/bin/bash
# Subindo o trackr
cd /home/deploy/trackr/current
mina up
# Subindo interfaces web, para acessar de fora
cd /scripts
sudo sh em1.sh
sudo sh interfaces.sh
@roberto-filho
roberto-filho / Snippet.java
Last active August 29, 2015 14:07
Bind a "method" to a button through reflection
protected void bindAction(Button btn, final String methodName) {
try {
final Method method = this.getClass().getMethod(methodName, new Class[] {});
btn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
method.invoke(GermantechEditor.this, new Object[] {});
} catch (Exception ex) {
ex.printStackTrace();
@roberto-filho
roberto-filho / apt.postgresql.org.sh
Created June 4, 2014 13:00
Script to add apt.postgresql.org to sources.list
#!/bin/sh
# script to add apt.postgresql.org to sources.list
# from command line
CODENAME="$1"
# lsb_release is the best interface, but not always available
if [ -z "$CODENAME" ]; then
CODENAME=$(lsb_release -cs 2>/dev/null)
fi
@roberto-filho
roberto-filho / add-fonts.sh
Created June 4, 2014 12:53
Adds microsoft fonts to your ubuntu
#!/bin/bash
# Install Microsoft Fonts (Including Tahoma)
if [ "$(id -u)" == "0" ]
then
if apt-get install msttcorefonts; then
mkdir temp-tahomafont
cd temp-tahomafont
if wget http://download.microsoft.com/download/ie6sp1/finrel/6_sp1/W98NT42KMeXP/EN-US/IELPKTH.CAB; then
cabextract IELPKTH.CAB
@roberto-filho
roberto-filho / query-ip.sql
Last active August 29, 2015 13:57
Query que busca os IPs dos ativos e suas respectivas localizações (servidor 192.168.0.106)
select a.*,
c.descricao,
l.nome
from componenteativo c
join ativo a on a.id = c.ativo_id
join localizacao l on l.id = a.localizacao_id
where c.componente_id = 23
and a.ativado is true