Skip to content

Instantly share code, notes, and snippets.

View DaddyMoe's full-sized avatar

Moses Mansaray DaddyMoe

View GitHub Profile
@DaddyMoe
DaddyMoe / ShouldHaveAPrivateConstructor.java
Last active December 18, 2017 10:03
Test private constructor - For the days you want to be predantic
/**
* For the days you want to be predantic
*/
@Test
public void shouldHaveAPrivateConstructor() throws Exception {
Constructor constructor = EuroSemanticResponse.class.getDeclaredConstructor();
assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
constructor.newInstance();
@DaddyMoe
DaddyMoe / ConvertObjectToEnumOneLineInstantiation.java
Created February 19, 2017 02:36
Converts Class Object to Enum equivalent
public class ConvertObjectToEnumOneLineInstantiation {
/*
* To:
`HIGHLIGHT("highlight", false, "field", false, "title,description,body", null),`
*
* From:
*
`HIGHLIGHT {
@DaddyMoe
DaddyMoe / TransportClientSniffingTestMain.java
Created February 19, 2017 02:37
TransportClient setup with Sniffing set to true to discover other nodes in the Elasticsearch cluster Raw
package com.euromoney.elasticsearch;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
public class TransportClientSniffingTestMain {
@DaddyMoe
DaddyMoe / JavaJunitParameterizedTest.java
Last active April 23, 2017 15:26
Java Junit Parameterized tests for when you are not in the mood to repeat yourself DRY: source: https://github.com/junit-team/junit4/wiki/Parameterized-tests
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@DaddyMoe
DaddyMoe / idea
Created March 15, 2017 15:11 — forked from chrisdarroch/idea
Open a project in IntelliJ IDEA from your command line!
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# were we given a directory?
if [ -d "$1" ]; then
# echo "checking for things in the working dir given"
wd=`ls -1d "$1" | head -n1`
@DaddyMoe
DaddyMoe / most_use_git_commands.md
Last active February 19, 2020 16:59
most use GIT commands I always seems to forget

Undoing the Last Commit

git reset --soft HEAD~1
  • Reset will rewind your current HEAD branch to the specified revision.

  • Effectively making our last commit undone.

  • The --soft flag: ensures undone revisions are preserved.

    git reset --hard HEAD~1

@DaddyMoe
DaddyMoe / most_use_bash_commands_I_never_remembers
Last active March 26, 2020 15:45
most use bash commands I never remembers - bash
# check for running java apps
ps xfau | grep java
# Or via program grep for java
pgrep -fl java
# Or via checking for port
lsof -i tcp:80
# Count files in current directory recursively
@DaddyMoe
DaddyMoe / dynamically_set_api_version.xml
Created March 24, 2017 11:54
Dynamically set API version in code from pom.xml. Great on CI where one is not manually tempering with versions.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
@DaddyMoe
DaddyMoe / Upload-image-to-S3
Created May 19, 2017 17:16
Upload image to S3
import java.io.IOException;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectMetadata;
@DaddyMoe
DaddyMoe / EmbeddedMongoTest.java
Created June 16, 2017 18:13
Example mongoDB embedded server
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoIterable;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.IMongodConfig;
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
import de.flapdoodle.embed.mongo.config.Net;