Skip to content

Instantly share code, notes, and snippets.

View pokk's full-sized avatar
🌀

Jieyi pokk

🌀
View GitHub Profile
@pokk
pokk / README.md
Created May 23, 2017 15:44
Make Mac speed up by using Ramdisk

Introduction

Script

We have this script for creating a ramdisk.

  • $((5x100x2048x2x__4__)) = 4096MB

You can change the number with bold and itan. Basic is 1024 * N size.

@pokk
pokk / README.md
Created May 29, 2017 09:09
Awaring a view is on measured or drawed by ViewTreeObserver

Introduction

If you can control your view size, for example as loading an imageview. You observe it then you can get the view size after the image is downloaded. You don't have to worry about when it is drawed and measured.

Example

OnCreate()

In Kotlin code:

@pokk
pokk / README.md
Last active July 1, 2017 04:13
Using one pic to simulate a clicking button

Interduction

How to do

First way

First step

@pokk
pokk / README.md
Created July 3, 2017 06:23
a Block, a Proc, a Lambda, and map class shorthand

[TOC]

Interduction

Using block, proc, lambda or shorthand for devleoping easily. We don't need to code so many words and coding style is elegant.

Map class shorthand

We're often using the simplest way to code a map lambda method. A well-known example:

@pokk
pokk / README.md
Created July 13, 2017 06:32
Do..End v.s Braces

What's difference between braces and do..end

Actually, there're no so big difference. But the priority is difference. We can check an example out as below then we can understand.

my_array = [1, 2, 3, 4, 5]

# <1>
p my_array.map { |item|
@pokk
pokk / README.md
Created July 28, 2017 02:48
Other way to expian 'if' and 'unless'

[TOC]

Introduction

How to do

Using if statment

@pokk
pokk / README.md
Created July 28, 2017 02:48
Tap a chain methods with condition statement.

Introcution

Sometimes we want to use chain method and Ruby also provides it.

It seems wonderful, BUT (Always BUT appears when everything is good 😭) the some chain methods only can run under some conditions. But we cannot do as like

obj.new
  .add(xxx) if xxx.present?  # Here will happen an error.
@pokk
pokk / README.md
Created July 28, 2017 02:50
zip and unzip

Zip

def zip_files(src_path, dst_path_with_filename='zipfile.zip'):
    """
    :param src_path: a list of the files you want to zip.
    :param dst_path_with_filename: the destination path with file name of the zip file.
    :return: None
    """
@pokk
pokk / README.md
Created August 1, 2017 02:44
What is `&&=` and `||=` meaning in ruby?

Introduction

Always I confuse &&= and ||=, what's difference between them?

Magic

operation &&=

a &amp;&amp;= b
@pokk
pokk / Using RxJava2 in `callback`..kt
Last active August 21, 2017 04:07
Introduction Instead of callback function hell, we will use an elegant way `RxJava2` to achieve it. How to do We can use `subject` or `processor`(with backpressure) to omit a callback function. Otherwise, if we just use an `observable`, it cant invoke `onNext` somewhere. Due to an `observable` will create so many new objects, using them is bette…
// A class
fun caller() {
// here we will set callback function.
callbackProcessor.subscriby {
// Here I can get `5566`, and do somthing.
}
}
// B class
fun callee() {