Skip to content

Instantly share code, notes, and snippets.

View Ikhiloya's full-sized avatar

Ikhiloya Ikhiloya

View GitHub Profile
@Ikhiloya
Ikhiloya / GetCustomAnnotation.kt
Created October 28, 2020 06:50
Get custom annotation from Invocation
if (invocation != null) {
val annotation: Cacheable? =
invocation.method().getAnnotation(Cacheable::class.java)
}
@Ikhiloya
Ikhiloya / GetInvocationByTag.kt
Created October 28, 2020 06:45
Shows how to get Invocation by tag from a Retrofit request.
var request = chain.request()
val invocation: Invocation? = request.tag(Invocation::class.java)
@Ikhiloya
Ikhiloya / NetworkInterceptor.kt
Last active October 28, 2020 10:18
Network interceptor for caching requests when there is network connection
class NetworkInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
Timber.d("network interceptor: called.")
val response = chain.proceed(chain.request())
val cacheControl = CacheControl.Builder()
.maxAge(5, TimeUnit.SECONDS)
.build()
@Ikhiloya
Ikhiloya / Cacheable.kt
Last active October 28, 2020 06:39
Custom annotation to mark a web service request for caching
@MustBeDocumented
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Cacheable {}
@Ikhiloya
Ikhiloya / Commands
Created August 19, 2020 06:09
Gradle and Maven Commands
mvn update ~= ./gradlew build --refresh-dependencies
mvn clean install ~= ./gradlew clean build
create user 'sa'@'localhost' identified by 'sa1234'; -- Create the user
grant all on exercise1.* to 'sa'@'localhost'; -- Gives all privileges to that user on new db
@Override
public ResponseEntity<Object> downloadFile(String fileName, HttpServletRequest request) throws Exception {
Storage storage = storageOptions.getService();
Blob blob = storage.get(BlobId.of(bucketName, fileName));
ReadChannel reader = blob.reader();
InputStream inputStream = Channels.newInputStream(reader);
byte[] content = null;
public String[] uploadFile(MultipartFile multipartFile) throws IOException {
File file = convertMultiPartToFile(multipartFile);
Path filePath = file.toPath();
String objectName = generateFileName(multipartFile);
Storage storage = storageOptions.getService();
BlobId blobId = BlobId.of(bucketName, objectName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
public String[] uploadFile(MultipartFile multipartFile) throws IOException {
System.out.println("bucket name====" + bucketName);
File file = convertMultiPartToFile(multipartFile);
Path filePath = file.toPath();
String objectName = generateFileName(multipartFile);
Storage storage = storageOptions.getService();
BlobId blobId = BlobId.of(bucketName, objectName);
@Ikhiloya
Ikhiloya / FirebaseStorageStrategyModified.java
Last active July 20, 2020 23:17
Storage Strategy for firebase upload and download with Admin SDK initialization in code
@Service
public class FirebaseStorageStrategy implements StorageStrategy {
private final Logger log = LoggerFactory.getLogger(FirebaseStorageStrategy.class);
private final Environment environment;
private StorageOptions storageOptions;
private String bucketName;
private String projectId;
public FirebaseStorageStrategy(Environment environment) {