Skip to content

Instantly share code, notes, and snippets.

@knownothingsnow
knownothingsnow / Array_unique.js
Created May 28, 2016 19:54
数组去重的ES5解法
function unique(arr) {
let n = []
arr.forEach((item, index) => {
if (n.indexOf(item) === -1) n.push(item)
})
return n
}
@knownothingsnow
knownothingsnow / browser-detector.js
Created June 8, 2016 03:31
通过user-agent检测浏览器环境
/*判断浏览器类型*/
let browser = {
versions: function() {
let u = navigator.userAgent, app = navigator.appVersion;
return {
trident: u.indexOf('Trident') > - 1, //IE内核
presto : u.indexOf('Presto') > - 1, //opera内核
webKit : u.indexOf('AppleWebKit') > - 1, //苹果 谷歌内核
gecko : u.indexOf('Gecko') > - 1 && u.indexOf('KHTML') == - 1,//火狐内核
mobile : ! ! u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端

前端开发常用命令和配置

Sass

$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
$ gem sources -l

确保只有 gems.ruby-china.org,遇到ssl证书问题,改用http

安装node-sass失败时,打开~/.npmrc,添加

.box {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
@knownothingsnow
knownothingsnow / Baymax.html
Created July 29, 2016 18:17
A Baymax animation made by CSS3
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Baymax</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="Baymax">
@knownothingsnow
knownothingsnow / star.js
Created June 18, 2017 02:56
一行代码生成星星评分
/**
* @func
* @desc 生成评分
* @param {number} rate [1-5]
* @returns {String}
*/
const getStar = (rate) => '★★★★★☆☆☆☆☆'.slice(5 - rate, 10 - rate)
fetch('https://stackoverflow.com')
.then(res => {
console.log('step1', res)
})
.then(res => {
console.log('step2')
throw new Error('borken here')
})
.then(res => {
console.log('step3')
@knownothingsnow
knownothingsnow / Auth.js
Created August 1, 2017 06:44
Front-end resource service layer with Fetch API
/**
* resource services of Auth page
*/
import http from './_Http.js'
export default http({
userInfo: {
url: '/api/auth/get-user',
type: 'json',
@knownothingsnow
knownothingsnow / Debian.md
Last active September 19, 2020 09:03
Debian 踩坑

Debian 踩坑

sudo locale-gen "en_US.UTF-8" //安装locale文件
sudo dpkg-reconfigure locales   //重新设置语言文件,如果跳转到设置页面,可以选择默认的即可。
sudo vi /etc/default/locale 改为如下

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
@knownothingsnow
knownothingsnow / regexCheatsheet.js
Created March 8, 2020 11:03 — forked from sarthology/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"