Skip to content

Instantly share code, notes, and snippets.

View bmutinda's full-sized avatar
🎯
Focusing

Mutinda Boniface bmutinda

🎯
Focusing
View GitHub Profile
@bmutinda
bmutinda / tutorial.md
Created July 17, 2018 07:24 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@bmutinda
bmutinda / MultiDexUtils.gist
Created February 23, 2017 12:36 — forked from mmadev/MultiDexUtils.gist
multidex utils
public class MultiDexUtils {
private static final String EXTRACTED_NAME_EXT = ".classes";
private static final String EXTRACTED_SUFFIX = ".zip";
private static final String SECONDARY_FOLDER_NAME = "code_cache" + File.separator +
"secondary-dexes";
private static final String PREFS_FILE = "multidex.version";
private static final String KEY_DEX_NUMBER = "dex.number";
@bmutinda
bmutinda / build.gradle
Created February 23, 2017 10:25 — forked from maheshwarLigade/build.gradle
Example of use from Proguard, from Android Studio
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
public class InstallListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// called in the install referrer broadcast case
}
}
@bmutinda
bmutinda / bump-version.sh
Created February 18, 2017 09:01 — forked from marteinn/bump-version.sh
This is a git hook for git-flow that I use for android studio that auto-bumps the project version and version code.
#!/bin/sh
# Bumps the version number to relevant files at the end of any release and hotfix start
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the release prefix)
# $4 The base from which this release is started
#
@bmutinda
bmutinda / .htaccess
Created October 7, 2016 06:45 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
public void animateTextView(int initialValue, int finalValue, final TextView textview) {
DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(0.8f);
int start = Math.min(initialValue, finalValue);
int end = Math.max(initialValue, finalValue);
int difference = Math.abs(finalValue - initialValue);
Handler handler = new Handler();
for (int count = start; count <= end; count++) {
int time = Math.round(decelerateInterpolator.getInterpolation((((float) count) / difference)) * 100) * count;
final int finalCount = ((initialValue > finalValue) ? initialValue - count : count);
handler.postDelayed(new Runnable() {
@bmutinda
bmutinda / SMSReceiver.java
Created August 4, 2015 14:01
SMS Receiver
/**
* Created by Mutinda Boniface on 7/12/2015.
*/
public class SMSReceiver extends BroadcastReceiver {
public static final String TAG = "SMSRelay";
public final String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public final String ACTION_PHONE_STATE_CHANGED = "android.intent.action.PHONE_STATE";
@Override
@bmutinda
bmutinda / SwipeEvents.java
Last active May 2, 2023 22:38
Android swipe events detector
package bmutinda.com.androidutils.libs;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by Mutinda Boniface on 7/5/2015.
*/
public class SwipeEvents implements View.OnTouchListener {
private SwipeCallback swipeCallback;