Skip to content

Instantly share code, notes, and snippets.

View rponte's full-sized avatar
🏠
Working from home

Rafael Ponte rponte

🏠
Working from home
View GitHub Profile
@Integralist
Integralist / Bankers Dilemma.md
Last active September 25, 2018 16:56
Bankers Dilemma

If we imagine the below diagram is an example of a bankers dilemma (two users Foo and Bar have access to a single bank account: Baz). What is the expected behaviour when following one of the paths shown?

Note: I'm assuming we're using a mutex (or some other form of synchronisation) on the Baz variable.

Example 1: Baz initially holds the value 10. If Foo writes a new value (which is the result of removing 5 from the current value) before Bar; then Bar will end up taking 10 from the new value 5, leaving a minus balance (i.e. the final value will be -5). Meaning more money has been taken than available.

Example 2: Baz initially holds the value 10. If Bar writes a new value (which is the result of removing 10 from the current value) before Foo; then Foo will end up taking 5 from the new value 0, leaving a minus balance (i.e. the final value will be -5). Meaning more money has been taken than available.

Both actions (Foo (-5) and Bar (-10)) are triggered at the same time. So how do we ensure that either

@garcia-jj
garcia-jj / GMailSender.java
Last active February 27, 2018 16:36
Sending email via GMail with Java SE environment
package br.com.otavio.mail.helper;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
@Specializes
@RequestScoped
public class CidLogicResult extends DefaultLogicResult {
private MutableRequest request;
public CidLogicResult(...., MutableRequest request) {
super(....);
this.request = request;
}
@Override
@staltz
staltz / introrx.md
Last active November 13, 2025 18:44
The introduction to Reactive Programming you've been missing
@kevinwright
kevinwright / scaladays2014.md
Last active November 16, 2024 17:40
Scaladays 2014 slides

As compiled by Kevin Wright a.k.a @thecoda

(executive producer of the movie, and I didn't even know it... clever huh?)

please, please, please - If you know of any slides/code/whatever not on here, then ping me on twitter or comment this Gist!

This gist will be updated as and when I find new information. So it's probably best not to fork it, or you'll miss the updates!

Monday June 16th

@donatasnicequestion
donatasnicequestion / ADFBeanValidator.java
Created June 7, 2014 20:55
ADF Bean Validator for JSF303 integration with Oracle ADF
package com.nicequestion.donatas.adf.validate;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.BeanValidator;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.ValidatorException;
@garcia-jj
garcia-jj / PersistentLocalDate.java
Last active August 29, 2015 14:00
JPA with java.time
/*
* Copyright 2014 Otávio S Garcia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alexandreaquiles
alexandreaquiles / Programa.java
Last active August 29, 2015 14:00
Passando objetos depois do construtor em JS no Rhino. Serve para implementar interfaces com uma sintaxe parecida com classes anônimas: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#jsimplement
import java.io.InputStreamReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Programa {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager factory = new ScriptEngineManager();
@alexandreaquiles
alexandreaquiles / CargaHorariaServidores.java
Last active September 16, 2025 14:40
Programa (em Java 8 vs grep) que pega as informações disponíveis no Portal da Transparência e sumariza a carga horária dos servidores públicos federais. Fonte dos dados: https://www.portaltransparencia.gov.br/download-de-dados/servidores/201402_Servidores_SIAPE
package cargaHorariaDosServidores;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.function.Function;
import java.util.regex.Matcher;
@Integralist
Integralist / PKI.md
Created April 10, 2014 08:41
Public-key infrastructure (PKI)

http://www.linux.com/community/blogs/133-general-linux/742528-pki-implementation-for-the-linux-admin

Public-key infrastructure (PKI) is what makes internet encryption and digital signatures work. When you visit your bank website you are told it is encrypted and verified.

How PKI Works

Most have heard the names of Verisign, Network Solutions, and GoDaddy. These companies along with many more are in the business of allowing the public to trust an organization's encryption keys and are referred to as Registration Authorities (RA)

If an organization, let’s say your bank, wants to encrypt their website that you use to manage your accounts they would first need to generate a private encryption key. The private key is something that should remain just that; private. With the private key one can extract a public key. While a public key can be created from a private key, the reverse should not be possible.