Skip to content

Instantly share code, notes, and snippets.

View tspoke's full-sized avatar
🎯
Focusing

Thibaud Giovannetti tspoke

🎯
Focusing
View GitHub Profile
struct DependencyInjector {
private static var dependencyList: [String:Any] = [:]
static func resolve<T>() -> T {
guard let t = dependencyList[String(describing: T.self)] as? T else {
fatalError("No povider registered for type \(T.self)")
}
return t
}
@craigzour
craigzour / PairingManager.kt
Created May 10, 2018 13:54
Here is a way of implementing pairing/bonding with RxAndroidBle
package hello.world
import android.bluetooth.BluetoothDevice
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.BroadcastReceiver
import com.polidea.rxandroidble2.RxBleDevice
import io.reactivex.Completable
import io.reactivex.disposables.Disposables
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@felipepastorelima
felipepastorelima / firestore.rules
Last active September 30, 2021 15:11
Firestore Rules utilities to reduce verbosity. Generator: https://scaffoldhub.io/firestore-rules
service cloud.firestore {
match /databases/{database}/documents {
// START - Usage example
match /people/{document=**} {
function propertiesValid() {
return request.resource.data.keys().hasAll(['name', 'birthdate', 'yearsOfExperience'])
&& request.resource.data.size() == 3
&& isString('name') && minlength('name', 3) && maxlength('name', 255)
@tspoke
tspoke / memo
Last active July 25, 2017 14:57
Simple monkey coded memo for terminal
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
EXPORT_FILE=$DIR'/memo-save.txt'
READ_ONLY=1
for param in "$@"
do
if [ $param = "edit" ]
then
READ_ONLY=0
@janakagamini
janakagamini / FirebaseUserIdTokenInterceptor.java
Last active June 4, 2021 06:36
A simple Interceptor to include a Firebase user's id token in all requests. Useful for authenticating Firebase users with a custom backend. See: https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients)
public class FirebaseUserIdTokenInterceptor implements Interceptor {
// Custom header for passing ID token in request.
private static final String X_FIREBASE_ID_TOKEN = "YOUR-CUSTOM-HEADER";
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
try {
@atoennis
atoennis / SomeFragment.java
Last active April 23, 2020 06:30
Solution to having nested scrolling within Android. In this scenario a multiline EditText resides within a root level ScrollView. In order to have scroll momentum, the EditText itself doesn't scroll but it is wrapped within a ScrollView.
// When the EditText is touched, disable touches on it's ScrollView's parents.
// Once the user lifts up their finger, enable touches on on the ScrollView's parents once again.
@OnTouch(R.id.edit_text)
boolean handleNoteFieldTouch(View v, MotionEvent event) {
v.getParent().getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
v.getParent().getParent().requestDisallowInterceptTouchEvent(false);
break;
@dcollien
dcollien / ImageTools.es6
Last active April 28, 2023 09:00
Resize Images in the Browser
let hasBlobConstructor = typeof(Blob) !== 'undefined' && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}());
let hasArrayBufferViewSupport = hasBlobConstructor && typeof(Uint8Array) !== 'undefined' && (function () {
try {
@alexbeletsky
alexbeletsky / 1.md
Last active May 17, 2017 07:32
Async.js vs Rx

Workflow Description

  1. Read records from database.
  2. For each record issue HTTP GET for a webservice and recieve a response.
  3. Store resonses to corresponding document back.
@jeroenvisser101
jeroenvisser101 / TorDetector.php
Last active September 29, 2019 10:59
Detecting people that use Tor
<?php
/**
* Class TorDetector
*
* Helps to detect if visitors are using a Tor browser to surf the website.
*
* Thanks to https://trac.torproject.org/projects/tor/wiki/doc/TorDNSExitList
*/
class TorDetector