Skip to content

Instantly share code, notes, and snippets.

View thuytrinh's full-sized avatar
💭
${null}

Thuý thuytrinh

💭
${null}
  • Frankfurt, Germany
  • 22:24 (UTC +02:00)
View GitHub Profile
@Grab(group = 'com.squareup.retrofit', module = 'retrofit', version = '1.6.1')
import retrofit.RestAdapter
import retrofit.http.GET
import retrofit.http.Query
interface WeatherService {
@GET('/forecast/webservice/json/v1')
Map find(@Query('city') String city)
}
@mattdenner
mattdenner / gist:dd4cfde3f355ff6b7be8
Last active May 18, 2016 18:52
From imperative to functional: functors, applicatives, monads & other link bait

I’ve been writing a load of Swift code recently for work and this has lead me into the world of typed functional programming. The app needs to build certain objects from a comma separated string, and this lead me to applicative functors, which lead me to brain ache but enlightenment. So here’s my thoughts on how I got to understand these a little better.

All of the code is in Swift, so less clean than Haskell. I’m also only a about 6 weeks into Swift development so I probably haven’t got all of the idioms right. I’ve avoided the optional shorthand wherever possible here, preferring Optional<Type> over Type? because I believe the latter is hiding something that helps understand this code in the context of other generic classes.

It’s also long! I think it’s probably the longest blog post I’ve ever written but I found it interesting and useful, for myself, to write. If you’re one of those people who skip to the end of a book to find out whodunit then I’ve included

@Aracem
Aracem / styles.xml
Last active July 11, 2017 15:48
Material Text Styles supported for all version with Appcompat + Calligraphy Library ( https://github.com/chrisjenx/Calligraphy ) Material Design recomendations http://www.google.com/design/spec/style/typography.html#typography-roboto-noto Remember to add the fonts to your source/fonts folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- TextView Empty Base-->
<style name="TextViewBase" parent="android:TextAppearance.Holo.Widget.TextView"/>
<!-- ActionBar Title -->
<style name="CustomActionBarTitleBase" parent="TextAppearance.AppCompat.Widget.ActionBar.Title"/>
<!-- Text Views Default Base -->
@LordRaydenMK
LordRaydenMK / FusedLocationProviderApi
Last active September 11, 2017 11:46
Using the FusedLocationProviderApi to request location updates
public class MainActivity extends Activity implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private LocationRequest mLocationRequest;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLocationRequest = LocationRequest.create();
/*:
This is an implementation of Algorithm W, as found in [Principal Types for functional programs](http://web.cs.wpi.edu/~cs4536/c12/milner-damas_principal_types.pdf).
We'll start by defining literals and expressions:
*/
enum Literal {
case string(String)
case int(Int)
@amlcurran
amlcurran / ColorAnimator.java
Last active July 18, 2018 11:24
Class which allows animation between two colors. Compatible with NineOldAndroids or the standard Android Animator APIs.
/**
* Copyright 2013 Alex Curran
*
* 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
@casidiablo
casidiablo / SimpleCursorLoader.java
Created September 14, 2011 20:03
Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview
/*
* Copyright 2012 CodeSlap - Cristian Castiblanco
*
* 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
@vvsevolodovich
vvsevolodovich / RxUgly.kt
Last active September 15, 2018 23:07
Ugly code written with RxJava due to lack of RxJava understanding
fun connectionObserveration(context: Context): Disposable? {
if ((firstObserver == null || firstObserver!!.isDisposed) && (secondObserver == null || secondObserver!!.isDisposed())) {
secondObserver = ReactiveNetwork.observeNetworkConnectivity(context)
.subscribeOn(AndroidSchedulers.mainThread())
.filter(ConnectivityPredicate.hasState(NetworkInfo.State.CONNECTED, NetworkInfo.State.DISCONNECTED))
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ connectivity ->
if (connectivity.state == NetworkInfo.State.CONNECTED) {
firstObserver = ReactiveNetwork.observeInternetConnectivity()
.subscribeOn(AndroidSchedulers.mainThread())
package org.paulbetts.shroom.core;
import android.os.AsyncTask;
import com.squareup.okhttp.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
package no.finn.android.contentprovider;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;