Skip to content

Instantly share code, notes, and snippets.

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

Rado Sohlich sohlich

🏠
Working from home
View GitHub Profile
// Restorer holds a function that can be used
// to restore some previous state.
type Restorer func()
// Restore restores some previous state.
func (r Restorer) Restore() {
r()
}
// Patch sets the value pointed to by the given destination to the given
@sohlich
sohlich / decorator.go
Created August 2, 2015 04:20
Example of decorator pattern in GO
package main
import (
"fmt"
"log"
)
//Basic interface to be enriched
type GreetingsBot interface {
DoHail(name string) (string, error)
//Generates variations of elements
//in submissionFiles array without repeating.
//output is array with tuples
for i := 0; i < len(submissionFiles); i++ {
for j := i + 1; j < len(submissionFiles); j++ {
tuple := OutputComparisonResult{
Files: []string{submissionFiles[i], submissionFiles[j]},
}
output = append(output, tuple)
}
// with no parameter
() -> System.out.println("Hello, world.")
// with a single parameter (This example is an identity function).
a -> a
// with a single expression
(a, b) -> a + b
// with explicit type information
//Old School
List<Transaction> groceryTransactions = new Arraylist<>();
for(Transaction t: transactions){
if(t.getType() == Transaction.GROCERY){
groceryTransactions.add(t);
}
}
Collections.sort(groceryTransactions, new Comparator(){
public int compare(Transaction t1, Transaction t2){
return t2.getValue().compareTo(t1.getValue());
@sohlich
sohlich / go test coverage
Created November 5, 2015 21:28
Test coverage in html for GO
go test -coverprofile cover.out
go tool cover -html=cover.out -o cover.html
@sohlich
sohlich / jboss-deployment-structure.xml
Last active November 17, 2015 16:41 — forked from akerekes/jboss-deployment-structure.xml
JBoss deployment structure file to disable container provided logging
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="org.apache.commons.logging" />
<module name="org.apache.log4j" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
<module name="org.jboss.logmanager" />
<module name="org.jboss.logmanager.log4j" />
<module name="org.slf4j" />
@sohlich
sohlich / Wildfly: deployment-overlay
Created January 8, 2016 11:56
Wildfly CLI: The deployment overlay command
deployment-overlay add --name=myOverlay --content=/WEB-INF/web.xml=/myFiles/myWeb.xml,/WEB-INF/ejb-jar.xml=/myFiles/myEjbJar.xml --deployments=test.war,*-admin.war --redeploy-affected
^[a-z]{4}:/{2}[a-z]{0,3}\.?[a-z,0-9,\.]{1,}\.?[a-z]{0,}:?[0-9]{0,4}
@sohlich
sohlich / shiro.ini
Created August 6, 2016 10:44 — forked from dominicfarr/shiro.ini
example jdbcRealm configured in shiro.ini
[main]
ds = com.mysql.jdbc.Driver
ds.serverName = localhost
ds.user = user
ds.password = password
ds.databaseName = db_name
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.dataSource = $ds
jdbcRealm.permissionsLookupEnabled = true