Skip to content

Instantly share code, notes, and snippets.

View tfanme's full-sized avatar
🎯
Focusing

tfan tfanme

🎯
Focusing
View GitHub Profile
@tfanme
tfanme / xmlBodyParser.js
Created March 31, 2013 14:49
using xml2js to enable request body parsing for express
var express = require('express'),
var app = express();
var utils = require('express/node_modules/connect/lib/utils'), xml2js = require('xml2js');
function xmlBodyParser(req, res, next) {
if (req._body) return next();
req.body = req.body || {};
@tfanme
tfanme / validator.spec.js
Last active March 28, 2018 09:42
常用表单字段类型校验的正则表达式及测试用例
import test from 'ava';
import { expect } from 'chai';
import chai from 'chai';
import { forEach } from 'lodash';
test('额度', t => {
try {
const exp = /^([1-9](\d{0,9})?(\.\d{1,2})?|0(\.\d{1,2}))$/;
const goodCases = [
'1',
const fieldsToChildren = (data) => {
return data.map(item => {
if (!item.key) {
item.key = index
index += 1
}
if (item.fields) {
item.children = item.fields
delete item.fields
for (let i = 0; i < item.children.length; i++) {
/**
* 支持检索嵌套表格
* @param key
*/
getNestedRowByKey(key, data = this.state.data) {
if (data.some(item => item.key === key)) {
return data.filter(item => item.key === key)[0]
}
for (let i = 0; i < data.length; i++) {
const item = data[i]
@tfanme
tfanme / requestWithAjax.js
Created March 5, 2018 02:42
Common jQuery Ajax method wrapper
/**
* 公用 ajax 请求
*/
request: function (options) {
var defaultOptions = {
beforeSend: function (xhr) {
xhr.setRequestHeader('accept', 'application/json');
xhr.setRequestHeader('Accept-Language', 'en');
},
type: 'post',
@tfanme
tfanme / map.js
Created February 8, 2018 08:11
使用一个对象作为 React 组件的配置,从而实现动态生成组件内容
import React from 'react';
import { Input, Icon } from 'antd';
import styles from './index.less';
const map = {
UserName: {
component: Input,
props: {
size: 'large',
prefix: <Icon type="user" className={styles.prefixIcon} />,
@tfanme
tfanme / map.js
Created February 8, 2018 08:11
使用一个对象作为 React 组件的配置,从而实现动态生成组件内容
import React from 'react';
import { Input, Icon } from 'antd';
import styles from './index.less';
const map = {
UserName: {
component: Input,
props: {
size: 'large',
prefix: <Icon type="user" className={styles.prefixIcon} />,
@tfanme
tfanme / generateId.js
Created February 8, 2018 08:10
一个典型的闭包 + IIFE(Immediately-invoked function expression) F结合的例子
/**
* 一个典型的闭包 + IIFE(Immediately-invoked function expression) F结合的例子
*/
const generateId = (() => {
let i = 0;
return (prefix = '') => {
i += 1;
return `${prefix}${i}`;
};
})();
@tfanme
tfanme / main.js
Created February 8, 2018 06:52 — forked from kdzwinel/main.js
List all undefined CSS classes
/*
This script attempts to identify all CSS classes mentioned in HTML but not defined in the stylesheets.
In order to use it, just run it in the DevTools console (or add it to DevTools Snippets and run it from there).
Note that this script requires browser to support `fetch` and some ES6 features (fat arrow, Promises, Array.from, Set). You can transpile it to ES5 here: https://babeljs.io/repl/ .
Known limitations:
- it won't be able to take into account some external stylesheets (if CORS isn't set up)
- it will produce false negatives for classes that are mentioned in the comments.
#!/bin/bash
docker_desc="Dockerfile" # Dockerfile filename
image_name="yourimage" # Name and optionally tag of your image
file_extension=".tar" # File extension of saved file
gz_extension=".gz" # File extension of saved file after compression
# Dockerfile exist or not
if [ ! -e "$docker_desc" ]; then
echo "Dockerfile not found"