Yifei Kong

Apr 30, 2018

CSS 布局基础知识

布局

网页的布局是面向文档流的,也就是每个元素默认都是从左到右,从上到下依次排列的。当然就像文章一样,有些元素比如标题默认就会另起一行,并且单独占据这一行。

所有的元素都分为三类:inline、inline-block、和 block。

其中 block 元素占据了一行的位置,即使他们的宽度不够一行,并且他们有自己的宽度和高度,比如 h1 元素。

inline-block 结合了 inline 和 block 元素的特性,首先他布局是 inline 的,也就是不会另起一行,但是又可以设定单独的高度和宽度。

display: none 将会完全不渲染该元素, visibility: hidden 会渲染这个元素,只是在该显式的地方留下空白

使用 inline-box 的布局

定位

CSS 中元素的定位有如下几种,可以使用 position 指定

方法 说明
static …

Apr 11, 2018

[译] CSS 选择器备忘录(cheatsheet)

这两天打算写写爬虫,准备用 css 选择器来抽取内容,翻译了一篇文章,正好复习一下,这篇文章遵守 CC-BY-NC-SA 协议。

大多数的 web 开发者首先学会了 CSS。因为给 HTML 元素写样式规则的元素选择器都很容易理解和记忆。经过一点点练习之后,就会发现成组的 CSS 表达式非常的有必要,比如使用一个逗号分隔开选择器,就可以把同一个样式属性附加到不同的多个元素了。

使用标签选择器和分组的选择器当然也有不足,那就是他们会应用到所有的标签。很快你就会意识到有时候需要给一个特定的元素加上样式。对于大多数开发者来说,最简单的选择当然是使用 class 和 id 选择器了。但是很遗憾的是这样下去的话,整个页面就会充满各种奇奇怪怪的类了。

除了不管的给 HTML 添加纯粹用于应用样式的 class 和 id 之外,你也可以考虑使用高级的 CSS 选择器来给指定元素应用样式。高级的选择器大致可以分类为上下文选择器、属性选择器、伪元素选择器和伪类选择器。

元素选择器

元素选择器把样式应用到所有选中元素上,也是被使用最广泛的选择器 …

Apr 04, 2018

Android SharedPreference

用来在应用中存储键值对配置

context.getSharedPreferences("prefName", Context.MODE_PRIVATE) get SharedPreferecnes instance sharedPref.getXXX("keyName", defaultValue) get value from SharedPreferences sharedPref.edit() get editor(SharedPreference.Editor) editor.putXXX("key-name", value) put value editor.commit() commit the changes

Apr 04, 2018

Android 开发的一些 tips

Prefer Maven dependency resolution instead of importing jar files. If you explicitly include jar files in your project, they will be of some specific frozen version, such as 2.1.1. Downloading jars and handling updates is cumbersome, this is a problem that Maven solves properly, and is also encouraged …

Apr 04, 2018

Android 连接 WiFi

https://stackoverflow.com/questions/4249911/android-how-to-create-eap-wifi-configuration-programmatically

redirects to

https://stackoverflow.com/questions/4374862/how-to-programmatically-create-and-read-wep-eap-wifi-configurations-in-android

https://stackoverflow.com/questions/19170260/how-to-connect-to-wpa-eap-wifi-on-android-with-4-3-api

Android 6.0 changes

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-network

working methods

https://stackoverflow.com/questions/12486441/how-can-i-set-proxysettings-and-proxyproperties-on-android-wi-fi-connection-usin

get real ip https://stackoverflow.com/questions …

Apr 04, 2018

Maven Basics

From: http://tutorials.jenkov.com/maven/maven-tutorial.html

Introduction

Maven is built around the pom.xml file. In Maven, how to build your project is predefined in the Maven Build Life Cycles, Phases and Goals. The POM file describes what to build, but most often not how to build it …

Apr 04, 2018

使用 Gson 解析 json 文档

解析 json 有两种流派:

  1. event-driven json parse: iterate the document, not loading all into memory
  2. document-based json parse: load the full document into memory once for all.

在 Python 中可以很容易的解析json文件,Python 中的 json.loads 是 document-based。而在 java 中可以使用 event-driven的。个人感觉这种 event-driven 的解析方式是多此一举,json本来定位就是小型的数据传输和配置存储,如果生成了一个很大的 json,应该考虑换用xml了。

在 Java 中需要生成和 JSON …

Feb 24, 2018

安卓证书与代理自动配置

Go to Settings > Security > Install from storage.

install programatically can be achived by from command line, by moving certs to

replacing bks file solely is useless, it has to be combined with the password

https://github.com/danzeeeman/meerkat-decompiled/blob/master/io/fabric/sdk/android/services/network/PinningInfoProvider.java

set …

Nov 15, 2017

安卓开发中的Context

在安卓当中,Context几乎是无处不在的,每一个Activity是一个Context,每一个Service也是一个Context。

但是如果你新起了一个线程的话,你需要显式地把Context传递进去。

比如下面的例子:

public class DumpLocationLog extends Thread {
    LocationManager lm;
    LocationHelper loc;
    public DumpLocationLog(Context context) {
        loc = new LocationHelper();
        lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    }
    public void run() {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, loc);
    }
}

然后使用这个线程的时候,把this,也就是一个context的实例传递进去

new DumpLocationLog(this);

if you are in …

Nov 15, 2017

为安卓编译64位的dropbear

如何使用dropbear

这里主要是需要在安卓上生成 host key,以及把自己的公钥传到安卓上

dropbearkey -t rsa -f /data/local/dropbear_host_key # 在安卓上生成key
adb push ~/.ssh/id_rsa.pub /data/local/authorized_keys # 在宿主机把自己的密钥传过去
dropbear -F -E -r /data/local/dropbear_host_key -A -N root -C jk -R /data/local/authorized_keys # 按照给定的key启动dropbear
dropbear -P /data/local/dropbear.pid -r /data/local/dropbear_host_key -A …
Next → Page 1 of 6