Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
// local, node database
import level from 'pouchdb-adapter-leveldb'
import Pouchy from 'pouchy'
Pouchy.plugin(level)
type Fruit = {
type: string,
tastes: string
} const fruit = new Pouchy<Fruit>({name : 'fruit'})
const orange = await fruit.save({type : 'orange', tastes : 'delicious'})
var pouch = new PouchDB('mydb');
var doc = {_id : 'mydoc', title : "Guess who?", text : "It's-a me, Mario!"};
pouch.put(doc).then(function() {
return pouch.search({
query : 'mario',
fields : [ 'title', 'text' ],
include_docs : true,
highlighting : true
});
@phpsmarter
phpsmarter / Clamp函数.js
Created January 23, 2022 03:29
钳位函数
export const clamp = (x: number, min: number, max: number): number => {
if (x < min)
return min;
if (x > max)
return max;
return x;
};
gulp.task('js', function () {
gulp.src('./js/*.js')
.pipe(uglify())
.pipe(concat('all.js'))
.pipe(gulp.dest('./js'));
});
// 如果是 Safari 直接 return
if ( !(e.clipboardData && e.clipboardData.items) ) {
return;
}
// Mac平台下Chrome49版本以下 复制Finder中的文件的Bug Hack掉
if(cbd.items && cbd.items.length === 2 && cbd.items[0].kind === "string" && cbd.items[1].kind === "file" &&
cbd.types && cbd.types.length === 2 && cbd.types[0] === "text/plain" && cbd.types[1] === "Files" &&
ua.match(/Macintosh/i) && Number(ua.match(/Chrome\/(\d{2})/i)[1]) < 49){
return;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@phpsmarter
phpsmarter / map.js
Last active September 29, 2020 15:13
expo Map method
import React from 'react';
import { Platform} from 'react-native';
import { MapView,Location, Permissions,Constants } from 'expo';
export default class App extends React.Component {
state = {
location: null,
errorMessage: null,
};
@phpsmarter
phpsmarter / getGeolocation
Created March 30, 2018 02:23
expo method
import React, { Component } from 'react';
import { Platform, Text, View, StyleSheet } from 'react-native';
import { Constants, Location, Permissions } from 'expo';
export default class App extends Component {
state = {
location: null,
errorMessage: null,
};
var reduce = fn => (Arr, acc) => Arr.reduce(fn, acc);
var add = reduce((acc,x)=>acc+x);
add([1,2,3],0);// -> 6
@phpsmarter
phpsmarter / compose.js
Created March 29, 2018 01:18 — forked from jperasmus/compose.js
"compose" function that handles both sync and async functions
// Async compose
const compose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input));
// Functions fn1, fn2, fn3 can be standard synchronous functions or return a Promise
compose(fn3, fn2, fn1)(input).then(result => console.log(`Do with the ${result} as you please`))