Skip to content

Instantly share code, notes, and snippets.

@namhyun-gu
namhyun-gu / circle.java
Last active August 29, 2015 14:15
Circle Image
RoundedBitmapDrawable bitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
bitmapDrawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
bitmapDrawable.setAntiAlias(true);
/* Apply drawable to ImageView */
view.setImageDrawable(bitmapDrawable);
@namhyun-gu
namhyun-gu / circle_glide.java
Last active August 29, 2015 14:15
Circle Image (Glide)
Glide.with(getActivity())
.load("Insert URL")
.asBitmap()
.into(new BitmapImageViewTarget(view) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
super.onResourceReady(resource, glideAnimation);
RoundedBitmapDrawable bitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
bitmapDrawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
bitmapDrawable.setAntiAlias(true);
@namhyun-gu
namhyun-gu / index.html
Created February 16, 2015 05:03
Solve Polymer render problem
<!-- Added First Line -->
<!doctype html>
@namhyun-gu
namhyun-gu / merge.cpp
Last active April 15, 2019 19:46
Merge Sort (merge)
/*
Merge array
@param f_s : first_start
@param f_e : first_end
@param s_s : second_start
@param s_e : second_end
@param source : source array
*/
void merge(int f_s, int f_e, int s_s, int s_e, int* source) {
@namhyun-gu
namhyun-gu / main.cpp
Last active March 31, 2017 02:43
Data Structure - Sort
#include <iostream>
#include <stdlib.h>
using namespace std;
#define RAND_MAX_CAPACITY 100
#define LIST_SIZE 8
inline int getRandNumber() { return (rand() % RAND_MAX_CAPACITY) + 1; }
class List {
@namhyun-gu
namhyun-gu / edit.xml
Last active September 21, 2016 01:17
Remove toolbar top shadow
// Remove toolbar top shadow
// Base code is android studio new application template
// AndroidManifest.xml
<activity
android:name=".MainActivity"
android:label="@string/app_name"
- android:theme="@style/AppTheme.NoActionBar"> // Remove this line
+ android:theme="@style/AppTheme"> // Replace this line
// styles.xml
@namhyun-gu
namhyun-gu / BasicAuth.kt
Last active November 7, 2022 15:13
Basic Auth (Okhttp3)
// See also: http://stackoverflow.com/questions/22490057/android-okhttp-with-basic-authentication
// Uses authenticator
fun login(val id: String, val password: String) {
var client = OkHttpClient()
client.authenticator = object:Authenticator() {
@Throws(IOException::class)
fun authenticate(route: Route, response: Response): Request {
var credential = Credentials.basic(id, password)
var request = response.request
.newBuilder()
@namhyun-gu
namhyun-gu / quicksort.js
Last active January 13, 2017 02:14
Quicksort (Javascript)
'use strict';
function ArrayUtil() { }
ArrayUtil.prototype.show = function(arr, rowLength = 5) {
var lengthCount = rowLength;
arr.forEach(function(element) {
process.stdout.write(element + "\t");
lengthCount--;
if (lengthCount == 0) {
@namhyun-gu
namhyun-gu / MainFragment.kt
Last active June 15, 2017 07:47
Refactoring Playground/MainFragment.kt
package com.namhyun.playground
import android.content.Intent
import android.os.Bundle
import android.preference.Preference
import android.preference.PreferenceFragment
import android.preference.PreferenceScreen
import com.namhyun.playground.camera.BasicActivity
import com.namhyun.playground.firebase.DatabaseActivity
import com.namhyun.playground.location.LocationActivity
@namhyun-gu
namhyun-gu / RecyclerView.setHasFixedSize.java
Last active August 2, 2017 06:49
Meaning of RecyclerView.setHasFixedSize
// Reference document
// https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html#setHasFixedSize(boolean)
// stackoverflow: https://stackoverflow.com/questions/28827597/when-do-we-use-the-recyclerview-sethasfixedsize
RecyclerView recyclerView = findViewById(R.id.recyclerview_id);
recyclerView.setHasFixedSize(true); // Not depend on the adapter content.
recyclerView.setHasFixedSize(false); // Depend on the adapter content.