Skip to content

Instantly share code, notes, and snippets.

@lawvs
lawvs / LocationListener.java
Last active May 25, 2018 12:04
Android获取位置
LocationListener locationListener = new LocationListener() {
// Provider的状态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
// Provider被enable时触发此函数,比如GPS被打开
@Override
public void onProviderEnabled(String provider) {
Log.e(this.getClass().toString(), provider);
@lawvs
lawvs / PI
Last active April 14, 2017 13:44
π
const double pi = acos(double(-1));
@lawvs
lawvs / randstr.sh
Last active November 6, 2021 11:57
生成随机密码
#!/bin/bash
# 使用 openssl 生成密码
openssl rand -base64 12
# 使用 dd 命令生成密码
dd if=/dev/urandom bs=1 count=15 2>/dev/null|base64 -w 0
# 使用 md5sum 生成密码
date |md5sum
# 使用 gpg 工具生成密码
gpg --gen-random --armor 1 12
@lawvs
lawvs / hearder.lua
Last active May 25, 2018 12:01
nginx配置
-- lua添加hearder
ngx.header['TEST']= test;
@lawvs
lawvs / robots.txt
Last active January 19, 2018 02:48
禁止所有爬虫收录
User-agent: *
Disallow: /
@lawvs
lawvs / .gitattributes
Created January 19, 2018 02:52
git相关配置
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
@lawvs
lawvs / log.js
Last active February 18, 2018 13:29
js发送异常日志
window.addEventListener('error', function (e) {
const stack = e.error.stack;
let message = e.error.toString();
if (stack) {
message += '\n' + stack;
}
const xhr = new XMLHttpRequest();
xhr.open('POST', '/log', true);
xhr.send(message);
});
@lawvs
lawvs / main.js
Created February 26, 2018 02:25
html标签状态改变时改变html标题
document.addEventListener('visibilitychange', function () {
document.hidden ? document.title = '(●—●)喔哟,崩溃啦!'
: document.title = '(/≧▽≦/)咦!又好了!'
})
@lawvs
lawvs / editable.js
Created March 1, 2018 17:00
网页进入编辑模式
javascript:document.body.contentEditable='true';document.designMode='on'; void(0);
@lawvs
lawvs / highlights.js
Created March 2, 2018 01:54
高亮HTMLElement
/**
* Highlights text within a dom element.
*
* Specifically this is designed to work with the output
* positions of terms returned from a lunr search.
*
* @param {HTMLElement} element - the element that contains text to highlight.
* @param {MatchLocation[]} matches - the list of matches to highlight.
*/
module.exports = function (element, matches) {