Skip to content

Instantly share code, notes, and snippets.

View japharr's full-sized avatar
🏠
Working from away

Jelil Adesina japharr

🏠
Working from away
View GitHub Profile
@japharr
japharr / TxtParser.java
Created September 12, 2022 11:56
Text file parser
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
public class Record {
private String desId;
private String sourceId;
@japharr
japharr / generate-keys-for-jwt.sh
Created July 10, 2022 17:02
Generate public and private keys
#!/bin/bash
openssl genrsa -out private.pem 2048
openssl pkcs8 -topk8 -inform PEM -in private.pem -out private_key.pem -nocrypt
openssl rsa -in private.pem -outform PEM -pubout -out public_key.pem
@japharr
japharr / mongodb_query.js
Created March 9, 2022 23:58
Removed duplicates items from Db
// Using loop to delete duplicate items but one
db.amazon_sales.find({}, {asin:1}).sort({_id:1}).forEach(function(doc){
db.amazon_sales.remove({_id:{$gt:doc._id}, asin:doc.asin});
})
// indexing the field
db.amazon_sales.createIndex( { "asin": 1 }, { unique: true } )
@japharr
japharr / to_lowercase.js
Created March 9, 2022 23:54
Update MongoDb document's field to lowercase
db.myCollection.find().forEach(
function(e) {
e.username = e.username.toLowerCase();
db.myCollection.save(e);
}
)
@japharr
japharr / recursiveFlattening.java
Created February 6, 2022 18:38
Flatten JsonObject
private Stream<Map.Entry<String, Object>> recursiveFlattening(String key, Map.Entry<String, Object> entry) {
String jsonKey = entry.getKey();
Object jsonElement = entry.getValue();
if(key != null)
jsonKey = key + "/" + jsonKey;
final String res = jsonKey;
if (jsonElement instanceof JsonObject) {
@japharr
japharr / regex.txt
Created January 22, 2022 01:53
Username regex
^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
└─────┬────┘└───┬──┘└─────┬─────┘└─────┬─────┘ └───┬───┘
│ │ │ │ no _ or . at the end
│ │ │ │
│ │ │ allowed characters
│ │ │
│ │ no __ or _. or ._ or .. inside
│ │
@japharr
japharr / .java
Created February 25, 2017 08:36
Invoke a method every 5 seconds in Android
private final FIVE_SECONDS = 5000;
public void scheduleSendLocation() {
handler.postDelayed(new Runnable() {
public void run() {
sendLocation(); // this method will contain your almost-finished HTTP calls
handler.postDelayed(this, FIVE_SECONDS);
}
}, FIVE_SECONDS);
}
@japharr
japharr / .java
Created March 6, 2017 13:24
Spring Data MongoDB month aggregation
Criteria criteria = new Criteria().andOperator(
where("warehouse").is(warehouse),
where("date").gte(currentYear.getStart()),
where("date").lte(currentYear.getEnd())
);
ProjectionOperation dateProjection = project()
.and("amount").as("amount")
.and("date").extractYear().as("year")
.and("date").extractMonth().as("month");
@japharr
japharr / snippet.html
Created June 8, 2016 11:45
Font Awesome Verified Icons
<!-- Verifed Icons -->
<span class="fa fa-stack fa-lg">
<i class="fa fa-certificate fa-stack-2x" style="color: green"></i>
<i class="fa fa-check fa-stack-1x fa-inverse"></i>
</span>
<span class="fa fa-stack fa-lg">
<i class="fa fa-certificate fa-stack-2x" style="color: red"></i>
<i class="fa fa-close fa-stack-1x fa-inverse"></i>
</span>
@japharr
japharr / multiple_ssh_setting.md
Created June 21, 2020 01:57 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"