Skip to content

Instantly share code, notes, and snippets.

@nichbar
nichbar / Kotlin String toObject snippet with Gson.md
Last active February 18, 2019 06:15
Kotlin String toObject snippet with Gson

With the help of reified keyword, we can now access generic type without explicitly passing the class as a pararmeter.

Without reified:

fun <T: Any> String.toObject(c: KClass<T>): T {
    return Gson().fromJson(this, c.java)
}

val jsonObject = jsonString.toObject(JsonObject::class.java)
@nichbar
nichbar / 将iframe标签替换为a标签.md
Last active November 1, 2017 01:20
将iframe标签替换为a标签

因为 Aequorea 的文章页面不是用 WebView 渲染的,所以不支持 iframe ,于是用正则把 iframe 换成 a。

var text='<p>在日本文化中,赞赏一道拉面料理的美味,除了将面和汤全部吃光之外,吃面时吸溜的声音越大,也会被认为是对厨师和餐厅越尊重。</p><p>可是这种饮食习惯,在其他地区多少会显得尴尬。“就算不发出声音,面条也是好吃的啊。”“虽然很喜欢日本,但是这点多少会令人感到不适。”一些国外旅客对此事发表了自己的看法。为了专门描述这种尴尬,有网友发明了一个新词——“noo-hara(面尬)”,将英文单词中“noodle(面条)”和“harassment(骚扰)”的词头拼在一起而成。</p><p>为了解决这一矛盾,日本方便面制造公司日清食品株式会社发明了一款名叫“音彦(OTOHIKO)”的降噪叉子,试图在消费者食用面条的同时,从源头消除“吸溜声”。</p><p style=\"text-align: center;\"><iframe src=\"https://v.qq.com/iframe/player.html?vid=x056485injo&amp;tiny=0&amp;auto=0\" width=\"280\" height=\"218\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" data-type=\"video\" style=\"display:none\"></iframe></p><p>这款“降噪”的叉子并不便宜,售价14800日元(约合865元人民币),并且限量发售5000个。目前消费者可以在日清官网预约购买。</p><figure><img src=\"https://files.cbnweek.com/e0776f60844b3f0395bc9924d0ed5ed6_710x240\"><figcaption></figcaption></figure><p>“为吃一碗泡面,不仅要花十多倍的价格买个叉子,还要专门下一个手机App。”有网友在社交网络中留言。</p><p>早在2014年,巴西世界杯期间,日清首次使用日本武士的形象拍摄广告。在广告中,身穿武士服的年轻男孩在巴西街头和外
@nichbar
nichbar / 低关注模式.txt
Created August 14, 2017 12:49
Android System UI 低关注模式 (LOW_PROFILE)
在Medium上第一次见到滚动内容时隐藏状态栏大部分图标仅剩时间与电量的效果,遂Google之,可能是关键字不对,并没有找到API。
几天后在翻看SYSTEM UI注释时发现,该效果名叫"低关注模式(Low Profile Mode)",一行代码即可实现。
SYSTEM_UI_FLAG_LOW_PROFILE
Flag for setSystemUiVisibility(int): View has requested the system UI to enter an unobtrusive "low profile" mode.
This is for use in games, book readers, video players, or any other "immersive" application where the usual system chrome is deemed too distracting.
In low profile mode, the status bar and/or navigation icons may dim.