Skip to content

Instantly share code, notes, and snippets.

@logzh
logzh / .eslintrc.js
Created December 9, 2015 12:53 — forked from nkbt/.eslintrc.js
Strict ESLint config for React, ES6 (based on Airbnb Code style)
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": ["react"],
"ecmaFeatures": {
@logzh
logzh / redux-demo.js
Last active April 7, 2016 05:17
redux-demo
import { combineReducers, createStore } from 'redux'
var objectAssign = require('object-assign');
// Action
const ADD_CART = 'ADD_CART';
const SET_GOODS_COLLECT = 'SET_GOODS_COLLECT';
function addToCart(goods) {
return {
type: ADD_CART,
@logzh
logzh / webpack.config.js
Last active April 7, 2016 05:18 — forked from aermolaev/webpack.config.js
webpack处理zepto
/* Load Zepto as module */
module.exports = {
entry: "./app.js",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{ test: /zepto(\.min)?\.js$/, loader: "exports?Zepto; delete window.$; delete window.Zepto;" },
@logzh
logzh / react.getMore.js
Created April 7, 2016 05:15
react 底部向上滑动获取更多数据
//console.log(window.scrollY) // 文档在垂直方向已滚动的像素值。
//console.log(window.innerHeight) // 浏览器窗口的视口(viewport)高度(以像素为单位)
//console.log(document.body.scrollHeight)
//console.log(window.scrollY)
_.debounce(function() {
var props = this.props;
if (typeof window !== 'undefined') {
@logzh
logzh / changeTitle.js
Created June 13, 2016 06:47
如何通过 js 修改微信浏览器的title?
var $body = $('body');
document.title = ‘title’
// hack在微信等webview中无法修改document.title的情况
var $iframe = $('<iframe src="/favicon.ico"></iframe>').on('load', function() {
setTimeout(function() {
$iframe.off('load').remove()
}, 0)
}).appendTo($body)
// https://www.zhihu.com/question/26228251
# _*_ coding: utf-8 _*_
"""类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算"""
#-- 寻求帮助:
dir(obj) # 简单的列出对象obj所包含的方法名称,返回一个字符串列表
help(obj.func) # 查询obj.func的具体介绍和用法
#-- 测试类型的三种方法,推荐第三种
if type(L) == type([]): print("L is list")
@logzh
logzh / gist:9319c90841447144bf43c183862f5ccb
Created April 21, 2017 07:42 — forked from thomseddon/gist:3511330
AngularJS byte format filter
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
#!/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
@logzh
logzh / addEventListener
Created August 14, 2017 04:04
throttle
window.addEventListener('scroll', _.throttle(eventHandler, 200), false);
@logzh
logzh / main.go
Created January 17, 2018 07:28
Handling Database/ORM Connections W/ Iris
// method 1:
// using a middleware function to "inject" into the RequestContext a user value that is a
// struct containing application-level services (e.g orm/db).
package main
import "os"
import "fmt"
import "flag"
import "github.com/jinzhu/gorm"
import "github.com/kataras/iris"