Skip to content

Instantly share code, notes, and snippets.

View gunhansancar's full-sized avatar

Gunhan Sancar gunhansancar

View GitHub Profile
@gunhansancar
gunhansancar / fibonacci.kt
Last active March 12, 2022 09:04
Recursive vs Iterative with #Kotlin and #Fibonacci sequence
import java.time.Duration
import java.time.Instant
object Fibonacci {
fun recursive(n: Long): Long = if (n < 2) n else recursive(n - 1) + recursive(n - 2)
tailrec fun recursiveTail(n: Long, a: Long, b: Long): Long
= if (n < 1) a else recursiveTail(n - 1, b, a + b)
fun iterative(n: Long): Long {
@gunhansancar
gunhansancar / build.gradle
Created January 16, 2019 14:39
Google introduced a new App Bundle format to split apk files in smaller sizes when they're being installed on the client devices. However, this means that we cannot have dynamic language changes in our applications. To prevent that split we need to add extra lines in our build.gradle file inside the app folder. For more details: https://gunhansa…
android {
//...
//... removed for brevity
bundle {
language {
enableSplit = false
}
}
}
@gunhansancar
gunhansancar / VisualEffectViewExtensions.swift
Created February 16, 2017 13:49
In this gist you can find out how to fade in/fade out UIBlurEffect on UIVisualEffectView on iOS 10 and also earlier versions. Also added example ViewController to see how to use them in action. The below snippets are written in Swift3.
extension UIVisualEffectView {
func fadeInEffect(_ style:UIBlurEffectStyle = .light, withDuration duration: TimeInterval = 1.0) {
if #available(iOS 10.0, *) {
let animator = UIViewPropertyAnimator(duration: duration, curve: .easeIn) {
self.effect = UIBlurEffect(style: style)
}
animator.startAnimation()
}else {
@gunhansancar
gunhansancar / build.gradle
Last active May 6, 2019 16:17
This is a sample build.gradle file for your android libraries to change their artifact file names. You can find more information on http://gunhansancar.com/how-to-change-apk-file-name-in-android/
//apply plugin: 'com.android.library' //uncomment this line for android libraries
//apply plugin: 'com.android.application' //uncomment this line for android applications
def renameArtifact(variant, defaultConfig) {
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def fullName = output.outputFile.name
def projectName = fullName.substring(0, fullName.indexOf('-'))
output.outputFile = new File(
@gunhansancar
gunhansancar / MyFragment.java
Last active October 29, 2015 05:49
This is a sample fragment which demonstrates how to properly instantiate a fragment with arguments.
package com.gunhansancar.android.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
@gunhansancar
gunhansancar / AnimButton.java
Last active October 19, 2016 03:20
AnimButton is a custom ImageButton which is imitating the whatsapp's send button behavior. Basically, it will change the image source when you enter some text on the edittext and it will go back when you clear the edittext. You can also read more on http://gunhansancar.com/anim-button-inspired-by-whatsapp/
package com.gunhansancar.android.animbutton;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
@gunhansancar
gunhansancar / LocaleHelper.java
Last active April 8, 2021 12:34
While developing your awesome application, sometimes you are required to add a language change feature to your app on the fly. However, Android OS does not directly support this behaviour. And therefore, you need to solve this situation in some other ways. For more details see http://gunhansancar.com/change-language-programmatically-in-android/
package com.gunhansancar.changelanguageexample.helper;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.preference.PreferenceManager;