Skip to content

Instantly share code, notes, and snippets.

View DaddyMoe's full-sized avatar

Moses Mansaray DaddyMoe

View GitHub Profile
### Keybase proof
I hereby claim:
* I am daddymoe on github.
* I am daddy_moe (https://keybase.io/daddy_moe) on keybase.
* I have a public key ASAfMlHY38ZDURK5lBgy1PhSHjtBOxDt3wqhhtGukCZ9sAo
To claim this, I am signing this object:
@DaddyMoe
DaddyMoe / MergeTwoMapofStringListTogether.java
Last active April 6, 2019 21:47
Merge two Maps together of type: Map<String, List<String>>
// Merge two Maps together of type: Map<String, List<String>>
static BiFunction<Map<String, List<String>>, Map<String, List<String>>, Map<String, List<String>>> mergeMaps() {
return (Map<String, List<String>> map1, Map<String, List<String>> map2) -> {
Map<String, List<String>> mergedMapped = new HashMap<>(map1);
map2.forEach((String k, List<String> v) -> mergedMapped.merge(k, v, (strings, strings2) -> {
strings.addAll(strings2);
return strings;
})
);
@DaddyMoe
DaddyMoe / Elasticsearch_all_field_include_all_poc.es
Last active December 11, 2017 18:35
Elasticsearch _all_ field POC enabling, excluding field and not_analysed fields
// lets create our index
PUT /t
{
"mappings": {
"t": {
"_all": {
"enabled": true
},
"properties": {
"one": {
@DaddyMoe
DaddyMoe / SpringRestTemplateBasicAuthExample.java
Created June 22, 2017 17:12
Spring RestTemplate Basic Auth Example
public class SpringRestTemplateBasicAuthExample {
public static void main(String... args){
RestTemplate rt = new RestTemplate();
rt.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
rt.getMessageConverters().add(new StringHttpMessageConverter());
String uri = new String("https://some.api.provider.com/rest/authenticate");
String plainCreds = "user@awesome.com:sfdfsdf$%&^$%4";
@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;
@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 / 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 / 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 / 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 / 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`