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 / SecurePreferences.java
Created September 12, 2018 17:05
Android SecurePreferences
/*
* Copyright (C) 2015, Scott Alexander-Bown, Daniel Abraham
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@japharr
japharr / detect.java
Created December 6, 2017 00:01
Detect if new install or updated version (Android app)
public static boolean isFirstInstall() {
try {
long firstInstallTime = App.getContext().getPackageManager().getPackageInfo(getPackageName(), 0).firstInstallTime;
long lastUpdateTime = App.getContext().getPackageManager().getPackageInfo(getPackageName(), 0).lastUpdateTime;
return firstInstallTime == lastUpdateTime;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
}
}
@japharr
japharr / install.txt
Created August 31, 2017 03:22
Install/Upgrade Jhipster
To upgrade/install jhipster
------------------------------
delete the local node_modules in your project folder
do npm i generator-jhipster -g
do npm i generator-jhipster-entity-audit -g
run npm i in the project folder
@japharr
japharr / .kt
Created June 22, 2017 12:10
Displaying Date/Time Picker in Android
//var date: Calendar? = null
fun rescheduleInstallation() {
val currentDate = Calendar.getInstance()
val date = Calendar.getInstance()
DatePickerDialog(this, object : DatePickerDialog.OnDateSetListener {
override fun onDateSet(view: DatePicker, year: Int, monthOfYear: Int, dayOfMonth: Int) {
date?.set(year, monthOfYear, dayOfMonth)
TimePickerDialog(this@InstallationDetailActivity, TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
date?.set(Calendar.HOUR_OF_DAY, hourOfDay)
date?.set(Calendar.MINUTE, minute)
@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 / .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 / .sql
Created February 7, 2017 15:03
sample
SELECT r.*
FROM region r, vehicleparameters vp, vehicle v
WHERE r.region = vp.REGION_ID and v.id = vp.VEHICLE_ID
@japharr
japharr / .sql
Last active February 7, 2017 14:39
saveit
UPDATE vehicleparameters vp
SET vp.REGION_ID = 71003331 WHERE vp.VEHICLE_ID =
(
SELECT v.ID
FROM vehicle v
WHERE v.registrationno = 'BDG 384 AU'
);
UPDATE vehicleparameters vp
SET vp.REGION_ID = 71003331 WHERE vp.VEHICLE_ID =
@japharr
japharr / .txt
Created January 30, 2017 14:18
Sample
http://197.210.2.132/galooliDevKitService/galooliDevKitService.svc/json/GetDailyInformation?userName=progserver&userHost=mtnn-business&userOrg=zon_mtnn_business&password=sattrak&requestedUnits=1116440&startDate=2017-01-01&endDate=2017-01-16&requestedPropertiesStr=date,unit_id,unit_name,fuel_init,fuel_final
@japharr
japharr / BookResource.java
Last active November 28, 2016 09:49
How to use checkbox on jhipster table and delete selected rows.
...
@Inject
BookRepository bookRepository;
/**
* DELETE /books/:id : delete the "id" book.
*
* @param books the id of the book to delete
* @return the ResponseEntity with status 200 (OK)
*/