Skip to content

Instantly share code, notes, and snippets.

View underwindfall's full-sized avatar
🐌
Making Progress

Qifan Yang underwindfall

🐌
Making Progress
View GitHub Profile
@underwindfall
underwindfall / BarListParcelConverter.java
Created July 19, 2017 10:09 — forked from cmelchior/BarListParcelConverter.java
Using Parceler 1.0.3 with Realm
// Specific class for a RealmList<Bar> field
public class BarListParcelConverter extends RealmListParcelConverter<Bar> {
@Override
public void itemToParcel(Bar input, Parcel parcel) {
parcel.writeParcelable(Parcels.wrap(input), 0);
}
@Override
public Bar itemFromParcel(Parcel parcel) {
@underwindfall
underwindfall / HttpUtil.java
Created April 17, 2017 18:03
HttpURLConnection网络请求工具类
/**
* HttpURLConnection网络请求工具类
*/
public class HttpUtil {
/**
* Get请求
*/
public static void sendGetRequest(
final String urlString, final HttpCallbackListener listener) {
// 因为网络请求是耗时操作,所以需要另外开启一个线程来执行该任务。
@underwindfall
underwindfall / TasksLocalDataSource.kt
Created April 4, 2017 08:16
Android Singleton Kotlin
//http://stackoverflow.com/questions/40398072/singleton-with-parameter-in-kotlin
class TasksLocalDataSource private constructor(context: Context) : TasksDataSource {
private val mDbHelper: TasksDbHelper
init {
// You cannot pass null in kotlin unless you are using `context: Context?`
// therefore, checking null is useless
// checkNotNull(context)
// 78: Promise - API overview
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Promise` API overview', function() {
it('`new Promise()` requires a function as param', () => {
const param = () => {};
assert.doesNotThrow(() => { new Promise(param); });
});
// 77: Promise - chaining
// To do: make all tests pass, leave the assert lines unchanged!
describe('chaining multiple promises can enhance readability', () => {
describe('prerequisites for understanding', function() {
it('reminder: the test passes when a fulfilled promise is returned', function() {
return Promise.resolve('I should fulfill.');
});
// 76: Promise - creation
// To do: make all tests pass, leave the assert lines unchanged!
describe('a promise can be created in multiple ways', function() {
describe('creating a promise fails when', function() {
it('using `Promise` as a function', function() {
function callPromiseAsFunction() {
Promise();
// 75: Promise - basics
// To do: make all tests pass, leave the assert lines unchanged!
describe('a Promise represents an operation that hasn`t completed yet, but is expected in the future', function() {
it('`Promise` is a global function', function() {
const expectedType = 'function';
assert.equal(typeof Promise, expectedType);
});
// 74: String - `endsWith()`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`str.endsWith(searchString)` determines whether `str` ends with `searchString`.', function() {
const s = 'el fin';
describe('1st parameter, the string to search for', function() {
it('works with just a character', function() {
const doesEndWith = s.endsWith('n');
// 73: Generator - `return` inside a generator is special
// To do: make all tests pass, leave the assert lines unchanged!
describe('`return` in a generator function is special', function() {
describe('the returned value is an IteratorResult (just like any value returned via `yield`)', function() {
it('returns an IteratorResult (an object with the properties `value` and `done`)', function() {
function* generatorFunction() { return 1; }
const returned = generatorFunction().next();
// 72: String - `startsWith()`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`str.startsWith(searchString)` determines whether `str` begins with `searchString`.', function() {
const s = 'the string s';
describe('1st parameter, the string to search for', function() {
it('works with just a character', function() {
const actual = s.startsWith('t');