Skip to content

Instantly share code, notes, and snippets.

@camiler
camiler / curry.js
Created June 15, 2022 08:21
jsbin.curry
// 一个需要curry的种子函数
const addSeed = (a, b) => a + b;
// 这种方式 必须明确f的参数是确定的
function curry(f) {
// 主要是把curried之后的参数不断累起来,直到参数个数达到f的参数个数后,直接调用f
return function curried(...args) {
// f.length是参数的个数
if (args.length >= f.length) {
return f(...args)
'use strict';
function counter(state, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
@camiler
camiler / index.html
Last active June 13, 2018 10:58
object assign// source http://jsbin.com/coquto
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>object assign</title>
</head>
<body>
<script id="jsbin-source-javascript" type="text/javascript">
var objectAssign = function(target, source) {
@camiler
camiler / border1px.css
Created March 30, 2018 07:22
hack 1px border in ios
.border1px{
position: relative;
}
.border1px::after{
content: " ";
width: 200%;
height: 200%;
position: absolute;
border: 1px solid #FFFFFF;
transform-origin: top left;
@camiler
camiler / resetcheckbox.html
Created March 29, 2018 06:26
implement the checkbox style with css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta name="apple-touch-fullscreen" content="yes">
<meta name="format-detection" content="telephone=no,email=no">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<style type="text/css">
input[type="checkbox"]{
@camiler
camiler / resetFontSize.js
Created March 29, 2018 06:22
reset font size script used in mobile
!function (win, option) {
var count = 0,
designWidth = option.designWidth,
designHeight = option.designHeight || 0,
designFontSize = option.designFontSize || 20,
callback = option.callback || null,
root = document.documentElement,
body = document.body,
rootWidth, newSize, t, self;
@camiler
camiler / listScrollDemo.html
Created February 6, 2018 06:56
Marquee of prize demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>跑马灯</title>
<style type="text/css">
.listdroll-wrap{
width: 80%;
margin: 100px auto;
background-color: rgba(0,0,0,0.5);
@camiler
camiler / unitUtil
Created September 15, 2017 08:48
some functions to handle unit/number/date, etc.
/**
* 处理字节大小显示不同单位类型的描述
* @param imgTotalSize
* @returns {*}
*/
export const showImgSize = (imgTotalSize) => {
if (imgTotalSize === 0) return '0M';
const allSizeM = (imgTotalSize / 1024 / 1024).toFixed(2);
const allSizeKB = (imgTotalSize / 1024).toFixed(2);
if (allSizeKB < 0.01) {
@camiler
camiler / arrUtil.js
Created September 15, 2017 08:43
some functions to handle array
/**
* 从数组中移除某一项
* @param arr
* @param item
*/
export const removeItemFromArr = (arr, item) => {
const index = arr.indexOf(item);
const newArr = arr.slice();
newArr.splice(index, 1);
return newArr;
@camiler
camiler / imgUtil.js
Created September 15, 2017 08:39
some functions to handle img
/**
* 对于较小的图片 可以直接读取 做预览
* @param img
* @returns {Promise}
*/
export const getBase64 = (img) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener('load', () => {
const src = reader.result;