Skip to content

Instantly share code, notes, and snippets.

View salmaanahmed's full-sized avatar
💭
Software Engineer with tons of experience in Android | iOS | Flutter | Xamarin

Salmaan Ahmed salmaanahmed

💭
Software Engineer with tons of experience in Android | iOS | Flutter | Xamarin
View GitHub Profile
@salmaanahmed
salmaanahmed / ChatAdapter.kt
Created October 22, 2018 10:35
FlagChatAdapter Gist
package sasliderdemo.salmaan.ahmsal.com.flagchatadapter
import android.content.Context
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.Toast
import java.util.*
/**
* Created by salmaanahmed on 04/09/2018.
@salmaanahmed
salmaanahmed / FlagChatAdapter.kt
Created October 22, 2018 11:18
FlagChatAdaper RecyclerViewAdapter
package sasliderdemo.salmaan.ahmsal.com.flagchatadapter
import android.content.Context
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
@salmaanahmed
salmaanahmed / ChatAdapter.kt
Last active October 23, 2018 05:01
ChatAdapter extends FlagChatAdapter
package sasliderdemo.salmaan.ahmsal.com.flagchatadapter
import android.content.Context
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.Toast
import java.util.*
/**
* Created by salmaanahmed on 04/09/2018.
@salmaanahmed
salmaanahmed / item_animation_from_bottom.xml
Last active October 23, 2018 04:55
Extendable Flag Chat Adapter animation for recycler view
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fillAfter="true"
android:fromYDelta="99%p"
android:toYDelta="0%p" />
</set>
@salmaanahmed
salmaanahmed / Result.swift
Created January 28, 2019 11:25
The Result type forces the programmer to explicitly handle the failure and success cases before they can gain access to the actual value.
enum Result<Wrapped, Failure> {
case value(Wrapped)
case error(Failure)
}
@salmaanahmed
salmaanahmed / Helper.swift
Created January 28, 2019 11:31
This API expresses exactly the intended result (either an error or data and response, never all or none) and allows them to be handled much more clearly.
URLSession.shared.dataTask(with: url) { (result: Result<(response: URLResponse, data: Data), Error>) in // Type added for illustration purposes.
switch result {
case let .success(success):
handleResponse(success.response, data: success.data)
case let .error(error):
handleError(error)
}
}
@salmaanahmed
salmaanahmed / IsEven.swift
Created January 28, 2019 11:55
The problem with finding even number in swift
// Swift:
7 % 2 == 1 // true
-7 % 2 == 1 // false. -7 % 2 evaluates to -1
// Ruby and Python
7 % 2 == 1 // true
-7 % 2 == 1 // true
@salmaanahmed
salmaanahmed / Integers.swift
Created January 28, 2019 12:00
Add two computed properties, isEven and isOdd, and a function isMultiple to the BinaryInteger protocol.
// On protocol BinaryInteger
@_transparent
public var isEven: Bool { return _lowWord % 2 == 0 }
@_transparent
public var isOdd: Bool { return !isEven }
func isMultiple(of other: Self) -> Bool
@salmaanahmed
salmaanahmed / currentCompilationConditions.swift
Created January 28, 2019 12:05
Compilation conditions before swift 5
#if !swift(>=4.2)
// This will only be executed if the Swift version is less than 4.2.
#endif
#if !compiler(>=4.2)
// This will only be executed if the Swift compiler version is less than 4.2.
#endif
@salmaanahmed
salmaanahmed / NewCompilationConditions.swift
Created January 28, 2019 12:06
Compilation conditions in swift 5
#if swift(<4.2)
// This will only be executed if the Swift version is less than 4.2.
#endif
#if compiler(<4.2)
// This will only be executed if the Swift compiler version is less than 4.2.
#endif