Skip to content

Instantly share code, notes, and snippets.

View patrick-elmquist's full-sized avatar

Patrick Elmquist patrick-elmquist

View GitHub Profile
// ==UserScript==
// @name Github status check sort
// @namespace https://github.com/
// @version 1.1.2
// @description Sort the status checks on a PR by status and then by name
// @author Skjnldsv
// @match https://github.com/*/*/pull/*
// @icon https://github.githubassets.com/favicons/favicon.svg
// @grant none
// @updateURL https://gist.github.com/skjnldsv/eb7b894ae996affde4a7d0e00e0d80a1/raw/github-status-check-sort.user.js
@patrick-elmquist
patrick-elmquist / Makefile
Last active September 1, 2021 18:34
QMK user repo makefile
USER = pket
KEYBOARDS = lily58 kyria
PATH_lily58 = lily58
PATH_kyria = splitkb/kyria
all: $(KEYBOARDS)
.PHONY: $(KEYBOARDS)
$(KEYBOARDS):
@patrick-elmquist
patrick-elmquist / start_emulator.sh
Created March 4, 2019 06:42 — forked from itmammoth/start_emulator.sh
Start an android emulator with changing DNS server to Google public DNS
#!/bin/bash
EMULATOR=~/Library/Android/sdk/tools/emulator
if [ $# -ne 1 ]; then
echo "ERROR: Please specify the target AVD from the list below" 1>&2
$EMULATOR -list-avds 1>&2
exit 1
fi
$EMULATOR -avd $1 -dns-server "8.8.8.8,8.8.4.4"
fun RecyclerView.setupParallaxScrollListener() {
addOnScrollListener(object : OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val layoutManager = layoutManager as? LinearLayoutManager ?: return
val scrollOffset = recyclerView.computeHorizontalScrollOffset()
val offsetFactor = (scrollOffset % measuredWidth) / measuredWidth.toFloat()
val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
findViewHolderForAdapterPosition(firstVisibleItemPosition)?.let {
recyclerView.apply {
// Create and attach the adapter
adapter = ShowAdapter(tvShows)
// Configure to be a horizontal list
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
// Attach a snap helper, more on that below
PagerSnapHelper().attachToRecyclerView(this)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
... >
<ImageView
android:id="@+id/poster"
android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:clipChildren="false"
>
class ShowViewHolder(view: View) : ViewHolder(view) {
private val title = itemView.title
private val description = itemView.description
private val thumbnail = itemView.thumbnail
private val poster = itemView.poster
private val interpolator = FastOutLinearInInterpolator()
/**
* Offset the thumb and text with a factor [-1.0..1.0] of the total width
data class Show(
@StringRes val title: Int,
@StringRes val description: Int,
@DrawableRes val image: Int
)
class ShowAdapter(private val items: List<Show>) : RecyclerView.Adapter<ShowViewHolder>() {
init {
setHasStableIds(true)
}
override fun getItemCount() = items.size
override fun getItemId(position: Int) = items[position].hashCode().toLong()
override fun onCreateViewHolder(parent: ViewGroup, vt: Int) = ShowViewHolder(parent.inflate(R.layout.item_show))
override fun onBindViewHolder(holder: ShowViewHolder, position: Int) = holder.bind(items[position])
}