Skip to content

Instantly share code, notes, and snippets.

View tcw165's full-sized avatar
💭
building AI

TC Wang tcw165

💭
building AI
View GitHub Profile
_log("Before Observable");
// Create a "cold" observable.
Observable<Boolean> ob = Observable
// The "just" convert a boolean into an Observable.
.just(true)
// Transform the items emitted by an Observable by applying a function to each item.
.map(new Func1<Boolean, Boolean>() {
@Override
public Boolean call(Boolean aBoolean) {
_log("Before Observable");
// The publish operator makes it a HOT observable.
Observable<Integer> ob = Observable
.just(1)
// The operator transforms it to a hot observable.
.publish();
// Process the observable.
ob.connect();
@tcw165
tcw165 / CameraUtils.java
Last active April 4, 2016 23:04
Standalone useful methods for Android Camera.
// Copyright (c) 2016 boyw165
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
/**
* Insert a new {@link Whatever} instance in ascent/descent order.
*/
public void insertByWhateverOrder(List<Whatever> whatevers, Whatever one) {
// The complexity is O(nlog(n)). The list needs to be already sorted in
// natural sorting order. Searching in an unsorted array has an undefined
// result.
int position = Collections.binarySearch(whatevers, one);
if (position < 0) {
whatevers.add(-position - 1, one);
#!/usr/bin/env python
import httplib, urllib
import argparse
import json
import os
def analyseImages(fileStream):
"""
// Copyright (c) 2016-present boyw165
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@tcw165
tcw165 / View_dispatchTouchEvent.java
Last active December 20, 2016 09:18
dispatchTouchEvent sample of a View.java in the Android framework.
// Complete source code:
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L10023-L10025
public boolean dispatchTouchEvent(MotionEvent event) {
boolean result = false;
// Ignore ...
if (!result && onTouchEvent(event)) {
result = true;
}
@tcw165
tcw165 / ViewGroup_dispatchTouchEvent.java
Last active August 14, 2018 07:01
dispatchTouchEvent sample of a ViewGroup in the Android framework.
// Complete source code:
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewGroup.java#L2143-L2357
public boolean dispatchTouchEvent(MotionEvent ev) {
boolean handled = false;
// Ignore ...
final boolean intercepted;
if (actionMasked == MotionEvent.ACTION_DOWN
|| mFirstTouchTarget != null) {
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Shadow/Invisible Activity theme -->
<style name="AppTheme.Invisible" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
public class IapDelegateActivity extends AppCompatActivity {
/**
* The IAP task is successful.
*/
public static final String ACTION_IAP_OK = "my.intent.action.IAP_OK";
/**
* The IAP task is failed.
*/
public static final String ACTION_IAP_CANCELED = "my.intent.action.IAP_CANCELED";