Skip to content

Instantly share code, notes, and snippets.

View bmutinda's full-sized avatar
🎯
Focusing

Mutinda Boniface bmutinda

🎯
Focusing
View GitHub Profile
@swalkinshaw
swalkinshaw / tutorial.md
Last active November 13, 2023 08:40
Designing a GraphQL API

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.

@maheshwarLigade
maheshwarLigade / build.gradle
Created February 2, 2016 05:25 — forked from jackgris/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'
@rogerhu
rogerhu / EndlessRecyclerViewScrollListener.java
Last active October 6, 2022 04:42
Endless RecyclerView scrolling for different layout managers
public abstract class EndlessRecyclerViewScrollListener extends RecyclerView.OnScrollListener {
// The minimum amount of items to have below your current scroll position
// before loading more.
private int visibleThreshold = 5;
// The current offset index of data you have loaded
private int currentPage = 0;
// The total number of items in the dataset after the last load
private int previousTotalItemCount = 0;
// True if we are still waiting for the last set of data to load.
private boolean loading = true;
@styopdev
styopdev / pick-schema.js
Last active February 15, 2022 22:59
Get mongoose schema fields, excluding specified values, for lodash.
_.mixin({ pickSchema: function (model, excluded) {
var fields = [];
model.schema.eachPath(function (path) {
_.isArray(excluded) ? excluded.indexOf(path) < 0 ? fields.push(path) : false : path === excluded ? false : fields.push(path);
});
return fields;
}
});
// Example
public class InstallListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// called in the install referrer broadcast case
}
}
@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;
@homj
homj / GridSpanSizeLookupHelper.java
Last active June 30, 2022 02:39
A ItemDecoration to center the contents of a RecyclerView. This comes in handy when you want to build a responsive UI.
/*
* Copyright 2015 Johannes Homeier
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@twolfson
twolfson / index.html
Last active November 20, 2019 13:07
Proof of concept media key binding with atom-shell
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node.js <script>document.write(process.version)</script>
and atom-shell <script>document.write(process.versions['atom-shell'])</script>.
</body>
@wetzler
wetzler / gist:6909882
Last active May 16, 2020 13:13
This gist shows you how to run a retention analysis. I blogged about how to run a retention analysis here: https://keen.io/blog/47823687779/how-to-do-a-retention-analysis/
require 'rubygems'
require 'keen'
require 'json'
require 'date'
require 'active_support/all' #for datetime calculation e.g. weeks.ago.at_beginning_of_week
require 'simple_xlsx' #for outputting excel files
require 'cgi' #for URL encoding
#================================oOo===================================