Skip to content

Instantly share code, notes, and snippets.

View yccheok's full-sized avatar

Yan Cheng Cheok yccheok

View GitHub Profile
@yccheok
yccheok / test.xml
Created May 28, 2017 21:32
Better ripple effect for auto complete text view dropdown
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:id="@android:id/mask">
<color android:color="#ffffff"/> <!-- any color will do -->
</item>
<item>
<selector android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_pressed="true">
<color android:color="#10ffffff"/>
</item>
public class SignInFragment
@Override
public View onCreateView...
...
enhanceViewAnimatorWithForgotPasswordIfPossible(inflater, container);
enhanceViewAnimatorWithResetPasswordIfPossible(inflater, container);
this.viewAnimator.setDisplayedChild(2);
return v;
// Current code
public static ErrorResponse getErrorResponse (Response<?> response) {
final Gson gson = new Gson();
try {
String json = response.errorBody().string();
return gson.fromJson(json, ErrorResponse.class);
} catch (Exception e) {
android.util.Log.e(TAG, "", e);
}
@yccheok
yccheok / gist:405726623df261dfd648bbd941b0995c
Created June 23, 2017 18:41
show chooser for image file and camera
package com.theartofdev.cropcameraimage;
import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
public static void startAlarmBroadcastReceiver(Context context, long delay) {
Intent _intent = new Intent(context, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, _intent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
// Remove any previous pending intent.
alarmManager.cancel(pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delay, pendingIntent);
}
package org.yccheok.jstock.engine.websocket;
import android.util.Log;
import com.google.gson.Gson;
import org.yccheok.jstock.engine.Code;
import org.yccheok.jstock.engine.Subject;
import org.yccheok.jstock.network.Utils;
public static void hideKeyboard(Fragment fragment) {
InputMethodManager imm = (InputMethodManager) fragment.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(fragment.getView().getRootView().getWindowToken(), 0);
}
PS C:\Users\yccheok> docker volume create --name postgres_data --driver local
postgres_data
PS C:\Users\yccheok> dir $env:ALLUSERSPROFILE\docker\volumes
dir : Cannot find path 'C:\ProgramData\docker\volumes' because it does not exist.
At line:1 char:1
+ dir $env:ALLUSERSPROFILE\docker\volumes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\ProgramData\docker\volumes:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// this happens in android as well
if (JStockAutoCompleteTextView.this.isPerformingCompletion()) {
// We need to differentiate, whether "string" is from user
// typing, or drop down list selection. This is because when
// user perform selection, document change event will be triggered
// too. When string is from drop down list selection, user
// are not expecting any auto complete suggestion. Return early.
return;
{"earnings":["XOM","TWX","RDS-B","PG","RDS-A","MCO","FB","ISRG","WMT","SAN","BA","MDLZ","BABA","JNJ","GOOGL","EXPE","DPZ","BP","PCLN","WFC","IBM","SBUX","MSFT","SPGI","CMG","GOOG","GSK","NVDA","AMZN","KO","AAPL","BRK-B","DIS","MCD","MMM"],"insider_transactions":["XOM","TWX","RDS-B","PG","RDS-A","MCO","FB","ISRG","WMT","SAN","BA","MDLZ","BABA","JNJ","GOOGL","EXPE","DPZ","BP","PCLN","WFC","IBM","SBUX","MSFT","SPGI","CMG","GOOG","GSK","NVDA","AMZN","KO","AAPL","BRK-B","DIS","MCD","MMM"],"stock_prices":[{"code":"SBUX","fall_below":52.58},{"code":"NVDA","fall_below":165.32},{"code":"BRK-B","fall_below":160.0},{"code":"GOOGL","fall_below":950.0},{"code":"SAN","rise_above":7.0}],"token":"ewz3vlSwg1s:APA91bF-9YWWRDXhiyeFa6Vk7BzKyPuP4hZRSRkD_NS92CIoS0ccIWVkXYbnX-vDhAPbGQQ_nNYCv14ON0oIarkBpow4_MBZV5SXtktN1_gOHTQjbdxE2KleqCTGmJixCwo5LQ5fclnX"}