Skip to content

Instantly share code, notes, and snippets.

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

Andrew Chen yongjhih

🏠
Working from home
View GitHub Profile
@gilgoldzweig
gilgoldzweig / MockSharedPreference.kt
Last active October 14, 2024 14:12
Mock implementation of shared preference, which just saves data in memory using map.
package com.gilgoldzweig.mvp.preferences
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import java.util.HashMap
import kotlin.collections.set
/**
* Mock implementation of [SharedPreferences], which just saves data in memory using map.
*/
#!/bin/bash
<< ////
The script creates 'licenses' under '$ANDROID_HOME' and creates a file which proves
that the SDK license was accepted by the user.
Please copy this to your own account/gist/server. Every time there's an updated license, update the file with the new
license hash.
Legally if you run this script (or your own version of it), it means YOU accepted the license - don't trust someone else.
The hashes below are supposed to be taken from $ANDROID_HOME/licenses/android-sdk-license on YOUR machine, after you
@naoto-ogawa
naoto-ogawa / JOOX_wrap_sample.java
Last active June 14, 2021 03:12
JOOX wrap sample
package com.example.xml;
import org.joox.Match;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import 'dart:math' as math;
import 'package:flutter/material.dart';
void main() => runApp(TestApp());
class TestApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
@mmcc007
mmcc007 / run_tests.sh
Last active March 25, 2023 23:31
Run tests with code coverage on all packages in a Flutter repo and combine coverage data into a single file for reporting
#!/usr/bin/env bash
# remember some failed commands and report on exit
error=false
show_help() {
printf "usage: $0 [--help] [--report] [<path to package>]
Tool for running all unit and widget tests with code coverage.
(run from root of repo)
@timusus
timusus / CallResultAdapterFactory.kt
Last active March 24, 2023 16:10
Retrofit Error Handling
import retrofit2.Call
import retrofit2.CallAdapter
import retrofit2.Response
import retrofit2.Retrofit
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.util.concurrent.Executor
class CallResultAdapterFactory(private val responseErrorMapper: ((Response<*>) -> Error?)? = null) : CallAdapter.Factory() {
@guness
guness / CombinedLiveData.java
Last active May 15, 2023 14:10
LiveData merger that takes two live data inputs and a merger function. Merges two results using merger function, and returning result allowing null inputs and outputs. Input and out types are parametric. However only supports two live data inputs for now.
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.Observer;
import java.util.function.BiFunction;
public class CombinedLiveData<T, K, S> extends MediatorLiveData<S> {
@gildaswise
gildaswise / rounded_modal.dart
Last active October 7, 2021 09:39
A custom implementation of the showModalBottomSheet, with rounded corners
import 'dart:async';
import 'package:flutter/material.dart';
/// Below is the usage for this function, you'll only have to import this file
/// [radius] takes a double and will be the radius to the rounded corners of this modal
/// [color] will color the modal itself, the default being `Colors.white`
/// [builder] takes the content of the modal, if you're using [Column]
/// or a similar widget, remember to set `mainAxisSize: MainAxisSize.min`
/// so it will only take the needed space.
@X-Wei
X-Wei / sliver_appbar_with_tabs.dart
Created July 29, 2018 11:36
Demo of using SliverAppbar with tabs.
// Sliver appbar with tabs.
// Adapted from: https://stackoverflow.com/a/50858058
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: SilverAppBarWithTabBarScreen(),
));
class SilverAppBarWithTabBarScreen extends StatefulWidget {
import 'package:flutter/material.dart';
void main() => runApp(new MaterialApp(home: new app()));
class app extends StatefulWidget {
@override
_appState createState() => new _appState();
}
class _appState extends State<app> {