Skip to content

Instantly share code, notes, and snippets.

View fbencosme's full-sized avatar
🏠
Working from home

Fausto Bencosme fbencosme

🏠
Working from home
View GitHub Profile
@fbencosme
fbencosme / CountryCodes.json
Created June 1, 2017 22:01 — forked from Goles/CountryCodes.json
Country and Dial or Phone codes in JSON format
[{"name":"Israel","dial_code":"+972","code":"IL"},{"name":"Afghanistan","dial_code":"+93","code":"AF"},{"name":"Albania","dial_code":"+355","code":"AL"},{"name":"Algeria","dial_code":"+213","code":"DZ"},{"name":"AmericanSamoa","dial_code":"+1 684","code":"AS"},{"name":"Andorra","dial_code":"+376","code":"AD"},{"name":"Angola","dial_code":"+244","code":"AO"},{"name":"Anguilla","dial_code":"+1 264","code":"AI"},{"name":"Antigua and Barbuda","dial_code":"+1268","code":"AG"},{"name":"Argentina","dial_code":"+54","code":"AR"},{"name":"Armenia","dial_code":"+374","code":"AM"},{"name":"Aruba","dial_code":"+297","code":"AW"},{"name":"Australia","dial_code":"+61","code":"AU"},{"name":"Austria","dial_code":"+43","code":"AT"},{"name":"Azerbaijan","dial_code":"+994","code":"AZ"},{"name":"Bahamas","dial_code":"+1 242","code":"BS"},{"name":"Bahrain","dial_code":"+973","code":"BH"},{"name":"Bangladesh","dial_code":"+880","code":"BD"},{"name":"Barbados","dial_code":"+1 246","code":"BB"},{"name":"Belarus","dial_code":"+375","
public static class NetworkHelpers
{
public static IObservable<T> WithProgressDialog<T>(this IObservable<T> source, Activity act)
{
var p = new AlertDialog.Builder(act).Create();
p.Show();
return source.Finally(p.Dismiss);
}
}
public static class UiExtensions
{
public static IObservable<Keycode> RxKeyPressed(this EditText tv, bool ignoreBackKey = false) =>
Observable.Create((IObserver<Keycode> obs) => {
tv.SetOnKeyListener(new KeyUpPressedListener(obs, ignoreBackKey));
return () => tv.SetOnKeyListener(null);
});
public static IObservable<string> RxTextChanged (this TextView tv, int dueTimeMilliseconds = 500) =>
FromEventPattern<TextChangedEventArgs> (
@fbencosme
fbencosme / RxSignUp.cs
Last active April 24, 2017 20:11
Rx Android Xamarin - Signup form
// SignUp flow.
Observable.CombineLatest(
firstName .RxTextChanged(50).StartWith(string.Empty),
lastName .RxTextChanged(50).StartWith(string.Empty),
email .RxTextChanged(50).StartWith(string.Empty),
pwd .RxTextChanged(50).StartWith(string.Empty),
confirmPwd.RxTextChanged(50).StartWith(string.Empty),
gender .RxSelectedItem() .StartWith(0),
, Tuple.Create)
.SampleLatest(
import java.util.*;
import java.util.concurrent.*;
import static java.lang.System.out;
public class AsyncRandomPrimeNumbersApp {
public static void main(String[] args) throws Exception {
final List<PrimeAvgTask> tasks = new ArrayList<>();
@fbencosme
fbencosme / CircleTransform.java
Created July 14, 2016 21:36 — forked from julianshen/CircleTransform.java
CircleTransform for Picasso
/*
* Copyright 2014 Julian Shen
*
* 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
@fbencosme
fbencosme / gist:a3773382f371f26745149e16461b868b
Created June 8, 2016 12:03 — forked from dodyg/gist:5823184
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

fun googleSignInOptionsObservable() : Observable<GoogleSignInOptions> =
  Observable.just(
  GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
   .requestIdToken(activity.getString(R.string.default_web_client_id))
   .requestEmail()
   .build())

fun googleApiClientObservable(gso : GoogleSignInOptions) : Observable<GoogleApiClient> =
@fbencosme
fbencosme / gist:5b516a110dbb60be632e
Last active August 29, 2015 14:24
using java 8 options and streams vs list and null checking v2
public String cookie(String name) {
Cookie[] cookies = raw.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(name)) {
return cookie.getValue();
}
}
}
return null;
@fbencosme
fbencosme / gist:0f2502721ef9bef6da07
Last active August 29, 2015 14:24
using java 8 options and streams vs list and null checking
List<Class<?>> assignables = Arrays.asList(Request.class, Response.class, HttpServletRequest.class, HttpServletResponse.class);
void callMethod(final Method me, final HttpServletRequest request, final HttpServletResponse response) {
Optional.ofNullable(me).ifPresent(m -> {
Optional<Class<?>[]> typesStream = Optional.of(m.getParameterTypes());
typesStream
.filter(ctypes -> ctypes.length == 1)
.map(types -> types[0])