Skip to content

Instantly share code, notes, and snippets.

View ngima's full-sized avatar
🎯
Focusing

Ngima Sherpa ngima

🎯
Focusing
View GitHub Profile
@ngima
ngima / clean_code.md
Created October 8, 2023 09:33 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@ngima
ngima / Create Windows USB bootable on macOS.md
Created August 23, 2022 11:54 — forked from pavankjadda/Create Windows USB bootable on macOS.md
Create Windows USB bootable drive on macOS

Create Windows bootable drive on macOS

  1. Download Windows ISO (Windows 7 or latest) from Official Windows store
  2. Once download finished, double click on ISO image. Mac will mount this ISO images in Volumes.
  3. Skip to step 5 if you like command line options. Open 'Disk Utility' application, select your USB device under 'external' category. Look for field Device and copy that value (ex. disk4)
  4. Right click on your device and select Erase then use following information to fill popup window
Name => WINDOWS10
Format => MS-DOS (FAT)
Scheme => GUID Partition Map
@ngima
ngima / README.md
Last active May 19, 2022 04:18 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

In Android Native Development

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

@ngima
ngima / RecyclerView.Adapter.kt
Created June 9, 2021 04:56
Android Live Templates
//radapter
class $adapter$ : androidx.recyclerview.widget.RecyclerView.Adapter<$adapter$.ViewHolder>() {
var data: MutableList<$model$> = mutableListOf()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: android.view.ViewGroup, viewType: Int): ViewHolder =
@ngima
ngima / Logger.java
Created November 19, 2018 06:35
Android Logger Class
import android.util.Log;
public class Logger {
public static void d(String tag, String message) {
if (BuildConfig.DEBUG) Log.d(tag, message);
}
public static void e(String tag, String message) {
if (BuildConfig.DEBUG) Log.d(tag, message);
}
@ngima
ngima / CameraResult.java
Created August 21, 2018 13:56
Android Image Picker
@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_TAKE_PICTURE:
try {
Uri uri = getImageUri(Profile.this, ((Bitmap) data.getExtras().get("data")));
if (uri != null) {
InputStream iStream = getContentResolver().openInputStream(uri);
byte[] inputData = getBytes(iStream);
private fun displayLocationSettingsRequest(context: Context) {
var googleApiClient = GoogleApiClient.Builder(context)
.addApi(LocationServices.API).build();
googleApiClient.connect();
var locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
@ngima
ngima / HeaderInterceptor.java
Created May 8, 2017 09:15
Header Interceptor
public class HeaderInterceptor
implements Interceptor {
@Override
public Response intercept(Chain chain)
throws IOException {
Request request = chain.request();
request = request.newBuilder()
.addHeader("appid", "hello")
.addHeader("deviceplatform", "android")
.removeHeader("User-Agent")
@ngima
ngima / CharWeight.java
Last active April 24, 2017 06:07
Outputs the character weight like;
package com.yipl.myapplication;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@ngima
ngima / Singleton.java
Last active April 17, 2017 04:58
Singleton class that is thread, reflection and serialization safe
import java.io.Serializable;
public class Singleton implements Serializable {
private static volatile Singleton sInstance;
private Singleton() {
if (sInstance != null) {
throw new RuntimeException("Use getInstace() method to instantiate.")
}