Skip to content

Instantly share code, notes, and snippets.

View momvart's full-sized avatar

Mohammad Omidvar momvart

  • Simon Fraser University
  • BC, Canada
  • LinkedIn in/momvart
View GitHub Profile
@momvart
momvart / EpochConverter.asm
Last active January 29, 2019 06:53
MIPS assembly code that converts epoch to date and time parts
#MIPS equivalent of .NET DateTime.GetDatePart
#https://referencesource.microsoft.com/mscorlib/R/ff06f271f088f1a8.html
.macro push(%value)
addi $sp, $sp, -4
sw %value, 0($sp)
.end_macro
.macro pop(%storeTo)
lw %storeTo, 0($sp)
addi $sp ,$sp, 4
@momvart
momvart / ScrollLockableGridLayoutManager.kt
Last active May 3, 2020 10:46
A simple extension of GridLayoutManager which makes it possible to lock/disable/set the read-only scroll properties for your recyclerview
import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
class ScrollLockableGridLayoutManager(context: Context, spansCount: Int) : GridLayoutManager(context, spansCount) {
var canScrollVertically = true
override fun canScrollVertically(): Boolean =
if (!canScrollVertically) false
else super.canScrollVertically()
@momvart
momvart / StartLinearSmoothScroller.kt
Last active August 3, 2019 07:02
A simple android LinearSmoothScroller which scrolls to put the target item to the top of the RecyclerView
class StartLinearSmoothScroller(context: Context): LinearSmoothScroller(context) {
override fun getVerticalSnapPreference() = SNAP_TO_START
}
//Example
val smoothScroller = StartLinearSmoothScroller(context)
smoothScroller.targetPosition = 0 //replace with your target position
layoutManager.startSmoothScroll(smoothScroller)
@momvart
momvart / PIPExample.kt
Created August 3, 2019 10:41
A way of showing a PIP window on all apps
val windowManager = this.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val windowLayoutParams = WindowManager.LayoutParams()
windowLayoutParams.width = 300
windowLayoutParams.height = 300
windowLayoutParams.x = 400
windowLayoutParams.y = 400
windowLayoutParams.format = PixelFormat.TRANSLUCENT
windowLayoutParams.gravity = Gravity.TOP or Gravity.LEFT
if (Build.VERSION.SDK_INT >= 26)
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
@momvart
momvart / IDXData.java
Last active August 16, 2019 05:36
A set of utility classes to read MNIST IDX files. http://yann.lecun.com/exdb/mnist/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class IDXData {
protected final ArrayList<Integer> dimensions;
protected final byte[][] rawData;
@momvart
momvart / CircularProgressBar.kt
Last active August 28, 2021 14:07
My simple implementation of a circular progress bar with support of animation in Android
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.AnimationUtils
import android.view.animation.Interpolator
import org.jetbrains.anko.displayMetrics
import kotlin.math.absoluteValue
@momvart
momvart / ButtonHoldClickTriggerTouchListener.kt
Last active August 28, 2021 14:06
A touch listener that makes a touch-and-hold click trigger functionality for you view in Android.
import android.view.MotionEvent
import android.view.View
import androidx.core.view.postDelayed
import kotlin.math.max
class ButtonHoldClickTriggerTouchListener(
private val startDelay: Long = STANDARD_DELAY,
private val minDelay: Long = STANDARD_MIN_DELAY_BETWEEN_TRIGGERS,
private val delayReduce: Long = STANDARD_DELAY_REDUCE
) : View.OnTouchListener {
@momvart
momvart / LayoutGravityBindingAdapter.kt
Created April 3, 2020 15:15
Android binding adapter for `layout_gravity` attribute
@BindingAdapter("android:layout_gravity")
fun setLayoutGravity(view: View, gravity: Int) {
when (view.layoutParams) {
is LinearLayout.LayoutParams ->
(view.layoutParams as LinearLayout.LayoutParams).gravity = gravity
is FrameLayout.LayoutParams ->
(view.layoutParams as FrameLayout.LayoutParams).gravity = gravity
//Add more view groups here
}
}
@momvart
momvart / BLOSUM62.py
Created April 8, 2020 17:48
Simple BLOSUM62 implementation in python. Used for sequence alignment of proteins. Based on https://en.wikipedia.org/wiki/BLOSUM
BLOSUM62_MATRIX = [[4, 0, -2, -1, -2, 0, -2, -1, -1, -1, -1, -2, -1, -1, -1, 1, 0, 0, -3, -2],
[0, 9, -3, -4, -2, -3, -3, -1, -3, -1, -1, -3, -3, -3, -3, -1, -1, -1, -2, -2],
[-2, -3, 6, 2, -3, -1, -1, -3, -1, -4, -3, 1, -1, 0, -2, 0, -1, -3, -4, -3],
[-1, -4, 2, 5, -3, -2, 0, -3, 1, -3, -2, 0, -1, 2, 0, 0, -1, -2, -3, -2],
[-2, -2, -3, -3, 6, -3, -1, 0, -3, 0, 0, -3, -4, -3, -3, -2, -2, -1, 1, 3],
[0, -3, -1, -2, -3, 6, -2, -4, -2, -4, -3, 0, -2, -2, -2, 0, -2, -3, -2, -3],
[-2, -3, -1, 0, -1, -2, 8, -3, -1, -3, -2, 1, -2, 0, 0, -1, -2, -3, -2, 2],
[-1, -1, -3, -3, 0, -4, -3, 4, -3, 2, 1, -3, -3, -3, -3, -2, -1, 3, -3, -1],
[-1, -3, -1, 1, -3, -2, -1, -3, 5, -2, -1, 0, -1, 1, 2, 0, -1, -2, -3, -2],
[-1, -1, -4, -3, 0, -4, -3, 2, -2, 4, 2, -3, -3, -2, -2, -2, -1, 1, -2, -1],
@momvart
momvart / BWT_First_To_Last.py
Last active May 13, 2020 11:25
A generator for mapping of last to first column in BWT matrix. Input is a BW transform of DNA sequence.
#change this if you want to support other types of sequences
def get_char_index(c):
if c == 'A':
return 1
elif c == 'C':
return 2
elif c == 'G':
return 3
elif c == 'T':
return 4