Skip to content

Instantly share code, notes, and snippets.

View rbe's full-sized avatar

Ralf Bensmann rbe

View GitHub Profile
@rbe
rbe / Java8Lambdas.java
Last active January 2, 2023 18:39
Java 8 Lambdas
import java.util.Arrays;
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class Main {
private static void sort(String[] strings, Comparator comp) {
Arrays.sort(strings, comp);
}
@Grab(group = 'com.gmongo', module = 'gmongo', version = '0.8')
import com.gmongo.GMongo
class MongoTest {
static void main(String[] args) {
// Instantiate a com.gmongo.GMongo object instead of com.mongodb.Mongo
// The same constructors and methods are available here
def mongo = new GMongo()
// Get a db reference in the old fashion way
def db = mongo.getDB("gmongo")
/**
* Get disjunction (opposite of intersection) from two lists.
* @param a List
* @param b List
* @return List
*/
private List disjunct(List a, List b) {
(a + b) - a.intersect(b)
}
@rbe
rbe / php-fpm-flags.patch
Created October 2, 2012 11:21
php_fpm_flags patch
--- php-fpm.orig 2012-10-02 12:53:02.000000000 +0200
+++ php-fpm 2012-10-02 13:16:40.000000000 +0200
@@ -10,6 +10,8 @@
#
# Add the following line to /etc/rc.conf to enable php-fpm:
# php_fpm_enable="YES"
+# You can also supply flags to start php-fpm:
+# php_fpm_flags="-c /usr/local/etc/php.ini"
#
@rbe
rbe / user_entity_hashcode.java
Created September 26, 2012 09:38
hashCode Method of User Entity
@Override
public int hashCode() {
int result = username.hashCode();
result = 31 * result + (emailAddress != null ? emailAddress.hashCode() : 0);
return result;
}
@rbe
rbe / user_entity_equals.java
Created September 26, 2012 09:31
equals Method of User Entity
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OdiseeUser that = (OdiseeUser) o;
if (emailAddress != null ? !emailAddress.equals(that.emailAddress) : that.emailAddress != null) return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (!username.equals(that.username)) return false;
@rbe
rbe / user_entity_object_identity.java
Created September 26, 2012 09:21
Object identity of User entity
public static void main(String[] args) {
User user1 = new User();
System.out.println(user1);
User user2 = new User();
System.out.println(user2);
}
@rbe
rbe / UserEntityFacesConverter.java
Created September 26, 2012 08:58
Faces Converter for User entity, used for recipients
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
@FacesConverter("recipient")
public class RecipientConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
@rbe
rbe / entity_equals_method.java
Created September 26, 2012 08:53
Entity bean with equals method
import java.util.Calendar;
public class User {
private Long id;
private Long version;
private Calendar lastModified;
private String username;
private String emailAddress;
@rbe
rbe / pf_selectonemenu_converter.jsp
Created September 26, 2012 08:48
Primefaces selectOneMenu with converter
<p:column id="recipientName" headerText="Recipient" sortBy="#{t.recipient}" filterBy="#{t.recipient}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{t.recipient.firstname} #{t.recipient.lastname}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{t.recipient}" converter="recipient">
<f:selectItem itemLabel="Select One" itemValue=""/>
<f:selectItems value="#{userBean.users}" var="recipient" itemLabel="#{recipient.username}" itemValue="#{recipient.username}"/>
</p:selectOneMenu>