Skip to content

Instantly share code, notes, and snippets.

@imsardine
imsardine / RecyclerViewActionsExtension.java
Last active March 11, 2020 04:27
APIs that extend RecyclerViewActions
import android.support.test.espresso.AmbiguousViewMatcherException;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewAssertion;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.core.deps.guava.base.Predicate;
import android.support.test.espresso.core.deps.guava.collect.Iterables;
import android.support.test.espresso.core.deps.guava.collect.Iterators;
import android.support.test.espresso.util.TreeIterables;
@imsardine
imsardine / adb-record
Created December 29, 2016 00:34
How to circumvent time limit of the screenrecord command
#!/usr/bin/env sh
if [ "$#" -ne 1 ]; then
echo "Usage: adb-record <FILENAME>"
exit -1
fi
RECORDING_FILE=$1
TEMPDIR=`mktemp -d`
adb shell 'rm -rf /sdcard/screenrecord && mkdir /sdcard/screenrecord'
adb shell 'for i in `seq -f %02.0f 40`; do screenrecord /sdcard/screenrecord/$i.mp4; done' &
def hello():
print "Hello, Gist!"
__all__ = ['visible', 'cacheable', 'callable_find_by', 'property_find_by']
def cacheable_decorator(lookup):
def func(self):
if not hasattr(self, '_elements_cache'):
self._elements_cache = {} # {callable_id: element(s)}
cache = self._elements_cache
key = id(lookup)
if key not in cache:
@imsardine
imsardine / special_numbers
Last active August 29, 2015 14:13
Programming
print [i for i in xrange(2000, 3200 + 1) if (i % 7 == 0 and i % 5 != 0)]
@imsardine
imsardine / climb.py
Created January 7, 2015 03:44
[程式題] 有一個樓梯,你每次只能爬 1 階、3 階,或 5 階。請寫一個 function,傳入樓梯總長為 N 階,回傳總共有多少種走法。 例如:樓梯總長為 5 階,走法有「1、1、1、1、1」、「5」、「1、3、1」、「1、1、3」、「3、1、1」,共 5 種 (注意:要剛好走完、不得超過總長,且不能後退)
import sys
def main(steps):
print "# of combination(s): %s" % climb(int(steps))
def climb(steps, paces=[1, 3, 5]):
if steps <= 0: return 1
return sum([climb(steps - pace, paces) for pace in paces if pace <= steps])
if __name__ == '__main__':
@imsardine
imsardine / python_resources.md
Last active August 29, 2015 14:07 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@imsardine
imsardine / javascript_resources.md
Last active August 29, 2015 14:07 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@imsardine
imsardine / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@imsardine
imsardine / jenkinshelper.py
Last active August 29, 2015 14:05
To parameterize the level of fingerprint validation. So negative validity (fingerprint not known at server) may be treated as an error (ArtifactBroken).
import os, logging
from jenkinsapi.fingerprint import Fingerprint
from jenkinsapi.custom_exceptions import ArtifactBroken
__all__ = ['save_artifact', 'save_artifact_to_dir']
_log = logging.getLogger(__name__)
def save_artifact(artifact, fspath, strict_validation=False):
if os.path.exists(fspath):