tonglin0325的个人主页

Android学习笔记——Layout

下面列举了Android中Layout,Table,Menu,Checkbox,Listview,Button,Bundle的基本使用和demo

1.Layout:该工程的功能是实现LinearLayout

Android Layout有多种,比如:Layout,MixLayout,TableLayout等

以下的代码是MainActivity.java中的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.example.linearlayout;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class MainActivity extends Activity {

private TextView firstText;
private TextView secondText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

firstText = (TextView)findViewById(R.id.firstText);
secondText = (TextView)findViewById(R.id.secondText);

firstText.setText(R.string.firstText);
secondText.setText(R.string.secondText);
}
}

全文 >>

Mac下安装minikube

1.安装kubectl命令

1
2
brew install kubectl

如果想安装指定版本的kubectl

1
2
3
4
5
curl -LO "https://dl.k8s.io/release/v1.20.0/bin/darwin/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
sudo chown root: /usr/local/bin/kubectl

验证版本,会打印出client端和server端的版本,官方建议2个版本直接版本相差不要大于+/-1

1
2
3
4
kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:59:43Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.7", GitCommit:"132a687512d7fb058d0f5890f07d4121b3f0a2e2", GitTreeState:"clean", BuildDate:"2021-05-12T12:32:49Z", GoVersion:"go1.15.12", Compiler:"gc", Platform:"linux/amd64"}

  

2.下载和安装minikube

1
2
3
4
5
6
7
8
9
➜  /Users/lintong/Downloads $ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 68.6M 100 68.6M 0 0 9365k 0 0:00:07 0:00:07 --:--:-- 11.0M
➜ /Users/lintong/Downloads $ sudo install minikube-darwin-amd64 /usr/local/bin/minikube

Password:

参考

1
2
https://minikube.sigs.k8s.io/docs/start/

如果要安装指定版本的话,请到下面的地址下载

1
2
https://github.com/kubernetes/minikube/releases

比如安装v1.21.0版本

1
2
3
curl -LO https://github.com/kubernetes/minikube/releases/download/v1.21.0/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube

卸载minikube

1
2
3
minikube delete
rm -rf ~/.minikube

  

3.安装virtualbox

1
2
brew install virtualbox

  

4.使用virtualbox来启动minikube集群

参考:在Mac上基于virtualbox安装minikube

全文 >>

Mac下安装mongodb

1.添加mongo的仓库

1
brew tap mongodb/brew

2.安装mongodb

1
brew install mongodb-community@4.4

参考:Mac OSX 平台安装 MongoDB

安装成功

3.打开mongo shell

1
2
/usr/local/opt/mongodb-community@4.4/bin/mongo xxx:27017/your_db

如果是mongo 6.0的话,是没有mongo命令的,需要额外安装mongosh,下载地址

1
2
https://www.mongodb.com/try/download/shell

4.查询数据

查看db

1
2
show dbs

如果遇到not master and slaveOk=false的报错,可以执行如下命令

1
2
3
4
rs.slaveOk()
或者
rs.secondaryOk()

如果遇到Error: Authentication failed的报错,可能是缺少了–authenticationDatabase admin参数

1
2
/Users/lintong/Downloads/mongosh-1.9.1-darwin-x64/bin/mongosh mongodb://xxx:27017/test -u xxx --authenticationDatabase admin -p

其他参数参考:https://www.mongodb.com/docs/mongodb-shell/reference/options/

查询数据

1
2
db.getCollection("your_collection").find()

查询一条数据

1
2
db.getCollection("your_collection").findOne()

  

全文 >>

Spark学习笔记——rdd,dataframe和dataset转换

1.生成RDD

1
2
val rdd: RDD[(String, Int)] = sc.parallelize(Seq(("cat", 30), ("fox", 40)))

2.生成case class RDD

1
2
3
case class WordCount(word: String, count: Long)
val rdd: RDD[WordCount] = sc.parallelize(Seq(WordCount("dog", 50), WordCount("cow", 60)))

3.rdd转df,注意这里需要隐式转换

1
2
3
4
import spark.implicits._

val df = rdd.toDF()

4.rdd转ds,注意

全文 >>

使用tweak插件修改HTTP请求

tweak是一款可以对request请求的response进行修改的浏览器插件,区别于ModHeader只能对header进行修改,tweak可以对请求的request payload(收费)和response payload(免费)进行拦截和修改。

下图是tweak的界面

同类产品还有requestlytweak的修改HTTP请求response功能是免费的requestly修改API response和request body都是需要收费版本才提供支持

参考:requestly 代理插件

Firefox tweak插件安装地址

https://addons.mozilla.org/en-US/firefox/addon/tweak-extension/

Chrome tweak插件安装地址

https://chromewebstore.google.com/detail/feahianecghpnipmhphmfgmpdodhcapi

tweak的使用分成拦截请求修改请求2个步骤

1.拦截请求#

点击图中按钮

在浏览器中请求对应的接口

接下来在URL中输入接口的相关关键字,tweak就能找到这个接口

2.修改请求#

修改HTTP请求的response,比如我们将返回json中的技术修改成技术xxxx,产品修改成产品yyyy

然后取消request autocomplete,勾选extension

再次刷新页面发起请求,这时我们会发生页面中的信息已经被拦截和修改

参考:方便智能的chrome数据mock插件

Android学习笔记——download

1.该工程的功能是实现从网上的链接下载一个lrc文件和一个mp3文件

以下代码是MainActivity.java中的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.example.download;


import com.example.utils.HttpDownloader;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
private Button downloadTxtButton;
private Button downloadMp3Button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
downloadTxtButton = (Button)findViewById(R.id.downloadTxt);
downloadTxtButton.setOnClickListener(new DownloadTxtListener());
downloadMp3Button = (Button)findViewById(R.id.downloadMp3);
downloadMp3Button.setOnClickListener(new DownloadMp3Listener());
}

class DownloadTxtListener implements OnClickListener{
public void onClick(View v) {
HttpDownloader httpDownloader = new HttpDownloader();
int lrc = httpDownloader.downFile("http://play.baidu.com/data2/lrc/121017633/121017633.lrc", "voa/", "1201250291414036861128.lrc");
System.out.println(lrc);
}
}

class DownloadMp3Listener implements OnClickListener{
public void onClick(View v) {
// TODO Auto-generated method stub
HttpDownloader httpDownloader = new HttpDownloader();
int result = httpDownloader.downFile("http://cdn.y.baidu.com/yinyueren/532bfdb43a336a584533ff61a7289503.mp3", "voa/", "江南.mp3");
System.out.println(result);
}
}

}

全文 >>