Skip to content

Instantly share code, notes, and snippets.

View norfish's full-sized avatar
🎯
Focusing

李永翔 norfish

🎯
Focusing
View GitHub Profile
@norfish
norfish / middleware.js
Last active August 19, 2018 11:15
middleware_edit from koa
class Middleware {
constructor() {
this._middleware = []
}
use(...fns) {
fns.forEach(fn => {
if (typeof fn !== 'function') {
throw new TypeError('Middleware must be function!')
}
@norfish
norfish / javascript
Created July 30, 2018 07:44
tiny xhr-ajax
const tinyAjax = function tinyAjax(config) {
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest()
request.open(config.method.toUpperCase(), config.url, true)
request.timeout = config.timeout || 60000
// Listen for ready state
request.onreadystatechange = function handleLoad() {
if (!request || (request.readyState !== 4)) {
return;
}
#!/bin/sh
# create self-signed server certificate:
read -p "Enter your domain [www.example.com]: " DOMAIN
echo "Create server key..."
openssl genrsa -des3 -out $DOMAIN.key 1024
@norfish
norfish / toast.js
Created January 25, 2018 11:33
移动端touch toast,依赖 jquery
/**
* @desc: Toast
* @authors: yongxiang.li
* @date: 2016-08-10 18:49:05
*
* Toast('message')
*/
// TODO 增加位置自定义
@norfish
norfish / ios-scroll.js
Created October 23, 2017 09:21
ios-scorll for not overflow
/**
* author: fa-ge
* github: https://github.com/fa-ge/LocalScrollFix
*/
;(function() {
function createHeadTag() {
var styleNode = document.createElement('style')
styleNode.className = 'localscrollfix-head'
document.head.appendChild(styleNode)
@norfish
norfish / isElementVisible.js
Last active May 19, 2017 08:59
判断元素在是否在可视区域 check element in viewport(include part of)
// include part of the element
// 包含元素的一部分区域在可以区域
function isElementVisble(el) {
if(!el) {
return;
}
var viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var elPos = el.getBoundingClientRect();
@norfish
norfish / keyboard.js
Created July 15, 2016 11:37
keyboard events - rn
//安卓不支持willShow方法,统一在didShow中处理
RCTDeviceEventEmitter.addListener(Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', evt=> {
if (!writeStore.isLoggingin) {
dispatcher.dispatch({
namespace: 'write',
action: 'keyboardShow',
data: {
keyboardHeight: evt.endCoordinates.height
/** @jsx React.DOM */
var STATES = [
'AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI',
'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS',
'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR',
'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'
]
var Example = React.createClass({
@norfish
norfish / select.jsx
Last active August 29, 2015 14:18 — forked from jbottigliero/select.jsx
/** @jsx React.DOM */
define(['reactjs'], function(React){
return React.createClass({
getDefaultProps: function(){
return {
multiple: false
/*
name: 'mySelect'
Shell脚本编程30分钟入门
====================
## 什么是Shell脚本
### 示例
看个例子吧:
#!/bin/sh
cd ~
mkdir shell_tut
cd shell_tut