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 / 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"
@japharr
japharr / thumbnail.java
Created April 7, 2020 20:51
Creating thumbnail for video, image, folder or other file
private void bind(FileItem item) {
this.item = item;
if (item.isVideo()) {
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(
item.path, MediaStore.Video.Thumbnails.MINI_KIND);
image.setImageBitmap(thumbnail);
} else if (item.isImage()) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(item.path, bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap, itemView.getWidth(), itemView.getHeight(), true);
@japharr
japharr / gist:5961f85a4cd1dad6408d3953597a45a1
Created March 16, 2020 18:57
Creating Android Native SearchView in ActionBar
override fun onCreateOptionsMenu(menu: Menu): Boolean {
val searchItem: MenuItem? = menu.findItem(R.id.action_search)
if (searchItem != null) {
searchView = MenuItemCompat.getActionView(searchItem) as SearchView
searchView.setOnCloseListener {
searchView.onActionViewCollapsed()
Log.v("MainActivity", "setOnCloseListener: onClose")
true
}
@japharr
japharr / schema.sql
Created August 18, 2019 04:00 — forked from fernandomantoan/schema.sql
Schema for PostgreSQL to use with JdbcTokenStore (Spring Security OAuth2)
create table oauth_client_details (
client_id VARCHAR(256) PRIMARY KEY,
resource_ids VARCHAR(256),
client_secret VARCHAR(256),
scope VARCHAR(256),
authorized_grant_types VARCHAR(256),
web_server_redirect_uri VARCHAR(256),
authorities VARCHAR(256),
access_token_validity INTEGER,
refresh_token_validity INTEGER,