Skip to content

Instantly share code, notes, and snippets.

View zzdjk6's full-sized avatar

Thor(Shenghan) Chen zzdjk6

  • Palmerston North, New Zealand
View GitHub Profile
@zzdjk6
zzdjk6 / MBProgressHUD+Rx.swift
Created July 17, 2016 16:37
Convenient way to show MBProgressHUD while RxSwift signal executing
extension ObservableType {
func showHUDWhileExecuting(view: UIView) -> RxSwift.Observable<Self.E> {
dispatch_async(dispatch_get_main_queue()) {
MBProgressHUD.showHUDAddedTo(view, animated: true)
}
return self.doOn { (_) in
dispatch_async(dispatch_get_main_queue()) {
@zzdjk6
zzdjk6 / RxEventHub.java
Created April 7, 2017 17:40
RxEventHub.java
package io.github.zzdjk6;
import java.util.HashMap;
import rx.Observable;
import rx.subjects.PublishSubject;
@SuppressWarnings("WeakerAccess")
public final class RxEventHub {
@zzdjk6
zzdjk6 / ListView+RealSmoothScroll.kt
Created June 11, 2017 12:37
ListView+RealSmoothScroll.kt
import android.os.Handler
import android.view.View
import android.widget.AbsListView
import android.widget.AdapterView
// workaround for scrolling issue
// refer: https://stackoverflow.com/questions/11431832/android-smoothscrolltoposition-not-working-correctly
fun AbsListView.realSmoothScrollToPosition(position: Int) {
fun getChildAtPosition(view: AdapterView<*>, position: Int): View? {
val index = position - view.firstVisiblePosition
@zzdjk6
zzdjk6 / Operations.swift
Last active December 4, 2017 02:13
Compatible Layer: Commonly used Operations in RxSwift 2.x
public extension ObservableType {
public func subscribeNext(_ onNext: ((Self.E) -> Swift.Void)? = nil) -> Disposable {
return self.subscribe(onNext: onNext, onError: nil, onCompleted: nil, onDisposed: nil)
}
public func doOnNext(_ onNext: ((Self.E) -> (Swift.Void))? = nil) -> Observable<E> {
return self.do(
onNext: { (element) in
onNext?(element)
@zzdjk6
zzdjk6 / Disposables.swift
Created December 4, 2017 02:14
Compatible Layer: Commonly used Disposable Types in RxSwift 2.x
public class AnonymousDisposable: Cancelable {
public func dispose() {
self.disposableImpl.dispose()
}
public var isDisposed: Bool { return self.disposableImpl.isDisposed }
private var disposableImpl: Cancelable
@zzdjk6
zzdjk6 / dockerfile
Created August 13, 2018 08:32
Dockerfile: php-cli
FROM ubuntu:18.04
MAINTAINER THOR CHEN "<[email protected]>"
RUN apt-get update && apt-get install -y tzdata && rm -rf /var/lib/apt/lists/*
ENV TZ Pacific/Auckland
RUN apt-get update && apt-get install -y \
php7.2 \
php7.2-mbstring \
php7.2-mysql \
@zzdjk6
zzdjk6 / AxiosService.js
Last active August 19, 2018 23:19
Persisted GraphQL Queries with axios and SilverStripe 4: previous
import axios from "axios";
import StorageService from "./StorageService";
export default class AxiosService {
static getInstance(query, variables) {
let headers = {};
const user = StorageService.readUser();
if (user && user.Token) {
headers["Authorization"] = "Bearer " + user.Token;
}
@zzdjk6
zzdjk6 / AxiosService.js
Created August 19, 2018 23:19
Persisted GraphQL Queries with axios and SilverStripe 4: after
import axios from "axios";
import StorageService from "./StorageService";
import persistedQueryMapping from "../graphql/mapping.json";
import compress from "graphql-query-compress";
export default class AxiosService {
static getInstance(query, variables) {
let headers = {};
const user = StorageService.readUser();
if (user && user.Token) {
@zzdjk6
zzdjk6 / mysite.yaml
Created August 19, 2018 23:29
Persisted GraphQL Queries with axios and SilverStripe 4: YAML config
SilverStripe\GraphQL\PersistedQuery\JSONStringProvider:
mapping_with_key:
default: '{"mutation($songID:Int,$playlistID:Int){addSongToPlaylist(SongID:$songID,PlaylistID:$playlistID){ID ClassName LastEdited Created Title Description NumberOfSongs}}":"eaa0ae5c-818a-4cb4-936d-50da2fe3c9a9","mutation($input:ModelPlaylistCreateInputType!){createPlaylist(Input:$input){ID ClassName LastEdited Created Title Description NumberOfSongs}}":"75390ddb-8573-41dc-a956-abddad50b1b5","mutation($email:String!,$password:String!){createToken(Email:$email,Password:$password){ID FirstName Surname Email Token}}":"78b0294c-d6af-4922-9a88-7cb49626a2f9","query{readPlaylists{ID ClassName LastEdited Created Title Description NumberOfSongs}}":"934da2a0-3c04-4f54-baff-2e89598b84cb","query{readSongs{ID Title Length Artist Album Disc Track StreamFileURL}}":"683e444c-c393-46db-9deb-fc2a46ef5107","query($playlistID:ID!){readOnePlaylist(ID:$playlistID){ID ClassName LastEdited Created Title Description Songs{ID ClassName LastEdited Created
// 1. Define the constants
const FETCH_DATA_REQUEST: string = 'FETCH_DATA/REQUEST';
const FETCH_DATA_SUCCESS: string = 'FETCH_DATA/SUCCESS';
const FETCH_DATA_FAILURE: string = 'FETCH_DATA/FAILURE';
// 2. Define action creators
const fetchDataRequest: () => Action<void> = createAction(FETCH_DATA_REQUEST);
const fetchDataSuccess: (payload: DataType) => Action<DataType> = createAction(FETCH_DATA_SUCCESS);
const fetchDataFailure: (payload: Error) => Action<Error> = createAction(FETCH_DATA_FAILURE);