Skip to content

Instantly share code, notes, and snippets.

View youxiachai's full-sized avatar

youxiachai youxiachai

View GitHub Profile
public class SoftInputAssist {
private View rootView;
private ViewGroup contentContainer;
private ViewTreeObserver viewTreeObserver;
private ViewTreeObserver.OnGlobalLayoutListener listener = () -> possiblyResizeChildOfContent();
private Rect contentAreaOfWindowBounds = new Rect();
private FrameLayout.LayoutParams rootViewLayout;
private int usableHeightPrevious = 0;
public SoftInputAssist(Activity activity) {
@andymatuschak
andymatuschak / States-v3.md
Last active April 12, 2024 16:06
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@nutinshell
nutinshell / gist:1d463ab3321dd5fa0d6e
Created October 26, 2015 15:07
Surge - Bypass CN CIDR
bypass-tun = 0.0.0.0/8, 1.0.0.0/9, 1.160.0.0/11, 1.192.0.0/11, 10.0.0.0/8, 14.0.0.0/11, 14.96.0.0/11, 14.128.0.0/11, 14.192.0.0/11, 27.0.0.0/10, 27.96.0.0/11, 27.128.0.0/9, 36.0.0.0/10, 36.96.0.0/11, 36.128.0.0/9, 39.0.0.0/11, 39.64.0.0/10, 39.128.0.0/10, 42.0.0.0/8, 43.224.0.0/11, 45.64.0.0/10, 47.64.0.0/10, 49.0.0.0/9, 49.128.0.0/11, 49.192.0.0/10, 54.192.0.0/11, 58.0.0.0/9, 58.128.0.0/11, 58.192.0.0/10, 59.32.0.0/11, 59.64.0.0/10, 59.128.0.0/9, 60.0.0.0/10, 60.160.0.0/11, 60.192.0.0/10, 61.0.0.0/10, 61.64.0.0/11, 61.128.0.0/10, 61.224.0.0/11, 100.64.0.0/10, 101.0.0.0/9, 101.128.0.0/11, 101.192.0.0/10, 103.0.0.0/10, 103.192.0.0/10, 106.0.0.0/9, 106.224.0.0/11, 110.0.0.0/7, 112.0.0.0/9, 112.128.0.0/11, 112.192.0.0/10, 113.0.0.0/9, 113.128.0.0/11, 113.192.0.0/10, 114.0.0.0/9, 114.128.0.0/11, 114.192.0.0/10, 115.0.0.0/8, 116.0.0.0/8, 117.0.0.0/9, 117.128.0.0/10, 118.0.0.0/11, 118.64.0.0/10, 118.128.0.0/9, 119.0.0.0/9, 119.128.0.0/10, 119.224.0.0/11, 120.0.0.0/10, 120.64.0.0/11, 120.128.0.0/11, 120.192.0.0/10,
@slightfoot
slightfoot / MoveViewTouchListener.java
Created May 30, 2015 23:43
Move View Touch Listener Example
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
/**
* @author Simon Lightfoot <simon@demondevelopers.com>
*/
public class MoveViewTouchListener
implements View.OnTouchListener
{
@chrisyip
chrisyip / iojs.sh
Last active February 16, 2016 06:03
Get latest installed node from nvm path
#!/usr/bin/env sh
if [ -d "$(brew --prefix)/Cellar" ]; then
node=`find /usr/local/Cellar -name node | grep iojs/.*/bin/node`
if [ ! -z "$node" ]; then
$node $@
else
echo "io.js not installed"
fi
else
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Subscriptions - WHY</title>
</head>
<body>
<outline text="cool" title="cool">
<outline htmlUrl="http://kedebug.com/" title="kedebug" xmlUrl="http://kedebug.com/atom.xml" type="rss" text="kedebug"/>
<outline htmlUrl="http://lucida.me/" title="Lucida" xmlUrl="http://lucida.me/atom.xml" type="rss" text="Lucida"/>
<outline htmlUrl="http://www.alloyteam.com" title="Web前端 腾讯AlloyTeam Blog | 愿景: 成为地球卓越的Web团队!" xmlUrl="http://www.alloyteam.com/feed/" type="rss" text="Web前端 腾讯AlloyTeam Blog | 愿景: 成为地球卓越的Web团队!"/>
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy
@xingrz
xingrz / RealmAdapter.java
Last active May 22, 2020 19:46
A RecyclerView.Adapter-like Adapter that binds RealmResults to ListView
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import io.realm.RealmObject;
import io.realm.RealmResults;
public abstract class RealmAdapter<E extends RealmObject, VH extends RealmAdapter.ViewHolder>
extends BaseAdapter {
@dmarcato
dmarcato / strip_play_services.gradle
Last active December 21, 2022 10:10
Gradle task to strip unused packages on Google Play Services library
def toCamelCase(String string) {
String result = ""
string.findAll("[^\\W]+") { String word ->
result += word.capitalize()
}
return result
}
afterEvaluate { project ->
Configuration runtimeConfiguration = project.configurations.getByName('compile')
@sofish
sofish / jqLite.extra.js
Last active October 20, 2015 13:09
rewrite `parent` and `find` method for jqLite
angular.$ = angular.element;
// jqLite `.parent([selector])` 支持 selector
angular.$.prototype.parent = function(sel) {
if(!sel) return angular.$(this[0].parentNode);
var list = [].slice.call(document.querySelectorAll(sel))
, currentNode = this[0]
, ret;
while(currentNode.nodeName !== 'HTML') {