Git Product home page Git Product logo

blog's People

Contributors

genweiwu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blog's Issues

angular2 之video事件绑定

事件绑定

绑定事件,类似onerror要写成on-error

js写法

<video onpause="doc.videoPause(this)" onplay="doc.videoPlay(this)" onclick="doc.videoClick(this)" onerror="doc.videoError()"
    src="" width="100%" preload='auto' controls style="max-height: 600px;">
</video>

angular2写法

<video on-pause="videoPause(this)" on-play="videoPlay(this)" on-click="videoClick(this)" on-error="videoError()"
    src="" width="100%" preload='auto' controls style="max-height: 600px;">
</video>

angular2中使用公共的js

问题

现在要用一个a.js,但是a.js中调用了common.js中的公共方法。如何一起迁移到angular2项目中?

一开始的方法是:
在component.ts中

import 'assets/common.js';
import 'assets/a.js';

但是发现a.js无法调用到common.js中的方法

临时解决方法

在component.ts中

//import 'assets/common.js';
import 'assets/a.js';

在index.html中通过script标签引入 common.js。
目前看来是可行的。

angular2引入第三方js文件

问题

import 'ztree';

引入ztree报错,发现它会去下面的路径下查找。

[D:\iRTT_new\code\request_service\angular\node_modules\ztree]
[D:\iRTT_new\code\request_service\angular\src\ztree]

分析

直接import的效果是:
直接去node_moudle下面去找同名的文件夹,或者直接去src目录下查找

解决方案

直接在component.ts中加入

import 'assets/3rd/zTree/js/jquery.ztree.all.js';

angular2 http synchronize

问题:如何实现http同步请求

下面的方法无法正常返回希望的值

test(): boolean {
    this.service.getData(result => {
      console.log("return true");
      return true;
    });
    console.log("return false");
    return false;
  }

angular中实现类似jQuery.ready方法中调用功能

问题

想实现类似在jQuery.ready方法中调用一个函数的能力。
一开始使用 ngAfterViewChecked ,发现ngAfterViewChecked 函数会一直被触发。

解决

当前改用ngAfterViewInit来实现的。

如何处理浏览器前进后退

场景

实现一个类似左侧树,右侧页面的页面,右侧页面是一个iframe;
通过点击左侧的不同按钮,右侧展示不同页面。

问题

比如先点击按钮1,右侧展示iframe为333.html
再点击按钮2,右侧展示iframe为444.html
再点击按钮3,右侧展示iframe为555.html

这个时候,你点击回退按钮,会发现iframe页面回到444.html
再点击回退,iframe页面回退到333.html
(这些是浏览器自动记录历史自动支持的)

但是,你想做到回退的时候,左侧按钮也定位到对应按钮,却不好实现?

难点

你会发现,点击回退按钮,虽然iframe内容会改变,但是iframe的src根本不会改变。
虽然onload事件仍然会触发,但是js中读取src也是不变的

规避方法

当前参考的实现是,既然没法去有效监听iframe的src的改变,那么就在每个iframe的页面中,加载一个js方法去做这个动作。参考下方演示中控制台打印的内容!

elastic search智能搜索

参照的教程

Learning to Rank Demo

This demo uses data from TheMovieDB (TMDB) to demonstrate using Ranklib learning to rank models with Elasticsearch.

Install Dependencies and prep data...

This demo requires

  • Python 3+
  • Python elasticsearch and requests libraries
  • Python elasticsearch_xpack libraries if xpack support is necessary

An aside: X Pack

Using the LTR plugin with xpack requires configuring appropriate roles. These
can be setup automatically by prepare_xpack.py which takes a username and
will prompt for a password. After this is run settings.cfg must be edited to
uncomment the ESUser and ESPassword properties.

python prepare_xpack.py <xpack admin username>

Download the TMDB Data & Ranklib Jar

The first time you run this demo, fetch RankLib.jar (used to train model) and tmdb.json (the dataset used)

python prepare.py

Start Elasticsearch/install plugin

Start a supported version of Elasticsearch and follow the instructions to install the learning to rank plugin.

Index to Elasticsearch

This script will create a 'tmdb' index with default/simple mappings. You can edit this file to play with mappings.

python indexMlTmdb.py

Onto the machine learning...

TLDR

If you're actually going to build a learning to rank system, read past this section. But to sum up, the full Movie demo can be run by

python train.py

Then you can search using

python search.py Rambo

and search results can be printed to the console.

More on how all this actually works below:

Create and upload features (loadFeatures.py)

A "feature" in ES LTR corresponds to an Elasticsearch query. The score yielded by the query is used to train and evaluate the model. For example, if you feel that a TF*IDF title score corresponds to higher relevance, then that's a feature you'd want to train on! Other features might include how old a movie is, the number of keywords in a query, or whatever else you suspect might correlate to your user's sense of relevance.

If you examine loadFeatures.py you'll see how we create features. We first initialize the default feature store (PUT /_ltr). We create a feature set (POST /_ltr/_featureset/movie_features). Now we have a place to create features for both logging & use by our models!

In the demo features 1...n json are mustache templates that correspond to the features. In this case, the features are identified by ordinal (feature 1 is in 1.json). They are uploaded to Elasticsearch Learning to Rank with these ordinals as the feature name. In eachFeature, you'll see a loop where we access each mustache template an the file system and return a JSON body for adding the feature to Elasticsearch.

For traditional Ranklib models, the ordinal is the only way features are identified. Other models use feature names which make developing, logging, and managing features more maintainable.

Gather Judgments (sample_judgments.txt)

The first part of the training data is the judgment list. We've provided one in sample_judgments.txt.

What's a judgment list? A judgment list tells us how relevant a document is for a search query. In other words, a three-tuple of

<grade>,<docId>,<keywords>

Quality comes in the form of grades. For example if movie "First Blood" is considered extremely relevant for the query Rambo, we give it a grade of 4 ('exactly relevant'). The movie Bambi would receive a '0'. Instead of the notional CSV format above, Ranklib and other learning to rank systems use a format from LibSVM, shown below:

# qid:1: rambo
#
#
# grade (0-4)	queryid	 # docId	title
4	qid:1 #	7555	Rambo

You'll notice we bastardize this syntax to add comments identifying the keywords associated with each query id, and append metadata to each line. Code provided in judgments.py handles this syntax.

Log features (collectFeatures.py)

You saw above how we created features, the next step is to log features for each judgment 3-tuple. This code is in collectFeatures.py. Logging features can be done in several different contexts. Of course, in a production system, you may wish to log features as users search. In other contexts, you may have a hand-created judgment list (as we do) and wish to simply ask Elasticsearch Learning to Rank for feature values for query/document pairs.

Is collectFeatures.py, you'll see an sltr query is included. This query points to a featureSet, not a model. So it does not influence the score. We filter down to needed document ids for each keyword and allow this sltr query to run.

You'll also notice an ext component in the request. This search extension is part of the Elasticsearch Learning to Rank plugin and allows you to configure feature logging. You'll noticed it refers to the query name of sltr, allowing it to pluck out the sltr query and perform logging associated with the feature set.

Once features are gathered, the judgment list is fleshed out with feature value, the ordinals below corresponding to the features in our 1..n.json files.

4	qid:1	1:12.318446	2:9.8376875 # 7555	rambo

Train (train.py and RankLib.jar)

With training data in place, it's time to ask RankLib to train a model, and output to a test file. RankLib supports linear models, ListNet, and several tree-based models such as LambdaMART. In train.py you'll notice how RankLib is called with command line arguments. Models test_N are created in our feature store for each type of RankLib model. In the saveModel function, you can see how the model is uploaded to our "movie_features" feature set.

Search using the model (search.py)

See what sort of search results you get! In search.py you'll see we execute the sltr query referring to a test_N model in the rescore phase. By default test_6 is used (corresponding to LambdaMART), but you can change the used model at the command line.

Search with default LambdaMART:

python search.py rambo

Try a different model:

python search.py rambo test_8

log4j中的Logger的name问题

比如

 Logger log = LogFactory.getLoger(A.class)

同时A在com.njust.test包下,
那么配置name时应该配置哪个呢?

Vue手记

Vue Devtools无法使用

chrome安装DevTools显示vue.js not detected

解决方法:

需要勾选扩展程序的允许访问文件网址

jackson读取测试

例子:junit测试

package com.njust.test.json;

import java.util.HashMap;

import org.junit.Assert;
import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class JsonTest
{
    @Test
    public void test01()
    {
        //由于不允许直接put null,所以模拟下
        String nullValue = new HashMap<String, String>().get("aa");

        ObjectMapper mapper = new ObjectMapper();
        ObjectNode objectNode = mapper.createObjectNode();
        objectNode.put("name", "111");
        objectNode.put("age", nullValue);

        //name
        String name = objectNode.get("name").asText();
        Assert.assertEquals(name, "111");

        //age
        String age = objectNode.get("age").asText(); //得到字符串:"null"
        Assert.assertEquals(objectNode.has("age"), true);
        Assert.assertNotNull(age);
        Assert.assertEquals(age, "null");

        String age2 = objectNode.path("age").asText(); //得到字符串:"null"
        Assert.assertEquals(age2, "null");
        String age3 = objectNode.path("age").asText(null); //得到null
        Assert.assertNull(age3);

        //country
        Assert.assertEquals(objectNode.has("country"), false);
        String country = objectNode.path("country").asText(); //得到空字符串:""
        Assert.assertNotNull(country);
        Assert.assertEquals(country, "");

        String country2 = objectNode.path("country").asText(null); //得到null
        Assert.assertNull(country2);

    }
}

angular2中,无法在component.css中去覆盖组件本身的样式

问题

例如,我在index.html中引入了ztreeStyle.css,我在自己的component.css中写了css想覆盖他的样式,
但是实际上没生效。

规避

在index.html中引入另一个css文件,在这个css文件进行样式覆盖。
但是对一个的缺点就是,无法针对单个组件进行样式调整。

property first does not exist on type observable

今天搭建项目遇到个问题

ERROR in D:/daveCode/adc-demo222/node_modules/st-angular-ui/core/a11y/focus-trap.ts (36,35): Property 'first' does not exist on type 'EventEmitter<any>'.
ERROR in D:/daveCode/adc-demo222/node_modules/st-angular-ui/core/a11y/focus-trap.ts (46,35): Property 'first' does not exist on type 'EventEmitter<any>'.
ERROR in D:/daveCode/adc-demo222/node_modules/st-angular-ui/icon/icon.ts (154,67): Property 'first' does not exist on type 'Observable<SVGElement>'.

有种说法是rxjs升级版本后api发生改变了

参照:angular/angular#15548

附上本地rxjs版本信息:

D:\daveCode\adc-demo222>npm list rxjs
[email protected] D:\daveCode\adc-demo222
+-- @angular/[email protected]
| `-- [email protected]
`-- [email protected]

grep的用法

查找当前文件夹下的xml文件,找出内容包含table-name的行的内容

grep "table-name" . -r --include *.xml

docker

入门

https://docs.docker.com/get-started/

镜像和容器

镜像是一个软件包,包括了软件本身以及软件运行所需的环境

容器则是由镜像启动的,即启动一个镜像得到一个容器,就是一个镜像的实例
docker ps用来查看当前机器上的容器

docker pull

~/.docker/config.json

 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "httpsProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
  • 国内镜像
  1. 修改 /etc/docker/daemon.json
{
 "registry-mirrors":["https://registry.docker-cn.com"]
}
  1. 重启docker
systemctl daemon-reload
systemctl restart docker
  • server gave HTTP response to HTTPS client

/etc/docker/daemon.json

{
    "insecure-registries": [
        "test.docker.jiankunking.io:5000", 
        "hub.docker.jiankunking.io:5000"
    ]
}

angular2中调用js中的方法

问题:在angular2中如何调用js中的方法

具体如下:
test.js中的方法

function hello() {
  console.log("Hello world!");
}
function hello222() {
  console.log("Hello world222222!");
}

在angular的component.ts中如何调用hello方法呢?

解决方法

  1. 修改test.js
    (注意:此时test.js改成test.ts)
export function hello() {
  console.log("Hello world!");
}

export function hello222() {
  console.log("Hello world222222!");
}
  1. 修改component.ts文件
import { hello,hello222 } from './test';

hello();
hello222();

参考这里的解决方法

  1. 变量的处理和上面的方法一样
export var vvv = function () {
  console.log("vvv is here!");
}

export var vvv222 = "this is a varible";
  1. 缺点
    需要将js改成ts,如果js改起来比较麻烦,就不好了

base的用法

*.car ==> *.jar

for file in *.car; do
    echo "$(basename "$file" .car).jar"
done

angular中使用ngOnChanges接口,但是没有触发

问题

今天遇到一个奇怪的问题,使用@input()描述了一个变量param,但是 ngOnChanges(changes: SimpleChanges)方法一直没法触发。

后来发现param的结构类似

param = {id:xxx}

如果只是修改id的属性,比如从

param=  {id:111}

修改成

param=  {id:222}

是无法触发的。

解决

后来发现,每次修改属性id前,都重新初始化 param={},再来设置他的属性,就能正常触发了。

理解

ngOnChanges的检测只检测了对象是不是之前的对象,而没有去检测同一个对象,但是内容修改了的情况。

spring支持自定义content-type

比如自定义的content-typeapplication/xxx

CustomerMessageConverter.java

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;

import com.fasterxml.jackson.databind.ObjectMapper;

public class CustomerMessageConverter implements HttpMessageConverter
{
    private MediaType supportedMediaType = MediaType.valueOf("application/xxx");

    private ObjectMapper mapper = new ObjectMapper();

    @Override
    public boolean canRead(Class clazz, MediaType mediaType)
    {
        return supportedMediaType.includes(mediaType);
    }

    @Override
    public boolean canWrite(Class clazz, MediaType mediaType)
    {
        return supportedMediaType.includes(mediaType);
    }

    @Override
    public List<MediaType> getSupportedMediaTypes()
    {
        return Collections.singletonList(supportedMediaType);
    }

    @Override
    public Object read(Class clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException
    {
        return mapper.readValue(inputMessage.getBody(), clazz);
    }

    @Override
    public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException
    {
        mapper.writeValue(outputMessage.getBody(), o);
    }
}

Application.java

@SpringBootApplication
public class Application
{
    public static void main(String[] args)
    {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public HttpMessageConverter customMessageConverter()
    {
        return new UeeMessageConverter();
    }

}

配置cntlm二级代理

配置cntlm二级代理

😺 windows上请使用exe版本安装,而不是zip解压版

1. 默认路径安装(否则有问题)

2. 修改配置

修改cntlm安装目录下的cntlm.ini,调整为自己需要的内容;
对于password,如果不想使用明文密码,可以先不设置;

如:

Username	dave
Domain		china
Password	password

3. 执行cntml- H进行初始化

此时会提示输入密码。
复制PassLM等信息到cntml.ini文件中对应位置。

C:\Program Files (x86)\Cntlm>cntlm.exe -H
"tty" option detected in CYGWIN environment variable.
CYGWIN=tty is no longer supported.  Please remove it from your
CYGWIN environment variable and use a terminal emulator like mintty,
xterm, or rxvt.
cygwin warning:
  MS-DOS style path detected: C:\Program Files (x86)\Cntlm\cntlm.ini
  Preferred POSIX equivalent is: /Cntlm/cntlm.ini
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Password:
PassLM          EE692D19A51BD430C9F8858E73320BF6
PassNT          A5D204104F5B09FEDCCFD9BFBC9C7251
PassNTLMv2      EB49E277191F47C788FDA722E6DB20ED    # Only for user 'dave', domain 'china'

如何配置文件路径不对,尝试指定路径

cntlm.exe -c cntlm.ini -H

4. 配置代理信息

Proxy		10.0.0.42:8080
Auth NTLM

5. 启动和停止

C:\Program Files (x86)\Cntlm>net start cntlm
Cntlm Authentication Proxy 服务正在启动 .
Cntlm Authentication Proxy 服务已经启动成功。


C:\Program Files (x86)\Cntlm>net stop cntlm
Cntlm Authentication Proxy 服务正在停止.
Cntlm Authentication Proxy 服务已成功停止。

vscode ignore spec.ts file

vscode如何忽略不显示 .spec.ts问题

打开vscode的工程的.vscode下的settings.json文件,
设置如下:

"files.exclude": {
    "**/*.spec.ts": true
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.