Skip to content

Instantly share code, notes, and snippets.

View hasanaga's full-sized avatar
🏠
Working from home

hasanaga

🏠
Working from home
View GitHub Profile
@Razeeman
Razeeman / Singletons.md
Last active November 9, 2023 19:23
Thread safe singleton implementations in java and kotlin.

Java

Not thread safe.

class SimpleSingleton {
    private static SimpleSingleton sInstance;
  
    private SimpleSingleton() {}
 
/*
* Copyright (C) 2017 The Android Open Source Project
*
* 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
public class SoftInputAssist {
private View rootView;
private ViewGroup contentContainer;
private ViewTreeObserver viewTreeObserver;
private ViewTreeObserver.OnGlobalLayoutListener listener = () -> possiblyResizeChildOfContent();
private Rect contentAreaOfWindowBounds = new Rect();
private FrameLayout.LayoutParams rootViewLayout;
private int usableHeightPrevious = 0;
public SoftInputAssist(Activity activity) {
@rd13
rd13 / .swift
Last active September 11, 2022 17:00
Copy database file from bundle to documents in Swift 3
func copyDatabaseIfNeeded() {
// Move database file from bundle to documents folder
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
guard documentsUrl.count != 0 else {
return // Could not find documents URL
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Request;
import com.squareup.picasso.RequestHandler;
@phileggel
phileggel / PrettyBytes.swift
Last active September 5, 2019 11:37
Converting Int bytes info to user-friendly String
//
// From Jody Hagins
// http://stackoverflow.com/questions/10091816/nsfilesystemfreesize-translating-result-into-user-friendly-display-of-mb-gb
//
// Converted to swift by phil on 30/11/2015.
// Copyright © 2015 PhilEagleDev. All rights reserved.
//
func prettyBytes(numBytes: Int) -> String {
let scale: Double = 1024