Skip to content

Instantly share code, notes, and snippets.

💭
Coding stuff

Geoff Hayward GeoffHayward

💭
Coding stuff
Block or report user

Report or block GeoffHayward

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@GeoffHayward
GeoffHayward / Generic
Last active Aug 20, 2019
java get column of multidimensional array
View Generic
private Object[] getColumn(int address, Object[][] from) {
return Arrays.stream(from).map(x -> x[address]).toArray(Object[]::new);
}
private <T> T[] getColumn(int address, T[][] from) {
return (T[]) Arrays.stream(from).map(x -> x[address]).toArray(Object[]::new);
}
@GeoffHayward
GeoffHayward / Setting up MySQL on Ubuntu 18.04
Last active May 28, 2019
Setting up MySQL on Ubuntu 18.04
View Setting up MySQL on Ubuntu 18.04
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
This seems to lock it down to the Ubuntu root user, therefore login using the Ubuntu root user
and run the following.
sudo mysql -u root
DROP USER 'root'@'%';
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
@GeoffHayward
GeoffHayward / HA Proxy (change a part of a URL)
Last active Jun 19, 2019
Redirect Configuration Examples
View HA Proxy (change a part of a URL)
http-request redirect code 301 location https://%[hdr(host)]%[url,regsub(^/example/,/demo/,)] if { path_beg /example/ }
View Add permission to host shared folders
sudo usermod -aG vboxsf $(whoami)
reboot
@GeoffHayward
GeoffHayward / .ebextensions iptables.config
Last active Nov 22, 2018
AWS Config: LB to Elasticbeanstalk over HTTPS
View .ebextensions iptables.config
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_update_iptables.sh":
mode: "000755"
owner: root
group: root
content: |
@GeoffHayward
GeoffHayward / App.java
Last active Feb 9, 2018
Abstract Builder Pattern
View App.java
public class App {
public static void main(String[] args){
Pizza nypizza = new NyPizza
.Builder(NyPizza.Size.LARGE)
.addTopping(Pizza.Topping.HAM)
.addTopping(Pizza.Topping.ONION)
.addTopping(Pizza.Topping.PEPPER)
.build();
System.out.println(nypizza.toString());
@GeoffHayward
GeoffHayward / App.java
Created Feb 9, 2018
The Basic Builder Pattern in Java
View App.java
public class App{
public static void main(String[] args){
Thing t = new Thing.Builder("a", "b", "c").prop5("e").prop4("d").build();
System.out.println(t.getProps());
}
}
View OutputStream.java
public final class OutputStream{
public static String capture(Consumer consumer){
PrintStream old = System.out;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
consumer.accept(consumer);
return baos.toString();
@GeoffHayward
GeoffHayward / Main.java
Last active Oct 27, 2017
Decorator Patten
View Main.java
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<ThingSubscriber> subscribers = new ArrayList<>();
subscribers.add(new ThingSubscriber("Subscriber 1"));
subscribers.add(new ThingSubscriber("Subscriber 2"));
@GeoffHayward
GeoffHayward / pom.xml
Created Aug 2, 2017
Mavan: Runnable Jar with Dependencies
View pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>eu.geoffhayward.application.Main</mainClass>
</manifest>
</archive>
You can’t perform that action at this time.