Skip to content

Instantly share code, notes, and snippets.

View codeyourwayup's full-sized avatar

FRANK GO codeyourwayup

View GitHub Profile
function setWithExpiry(key, value, ttl) {
const now = new Date()
// `item` is an object which contains the original value
// as well as the time when it's supposed to expire
const item = {
value: value,
expiry: now.getTime() + ttl,
}
localStorage.setItem(key, JSON.stringify(item))
import RestocksService from '../../../services/supreme/RestocksService';
import StorageService from '../../../services/StorageService';
import ChromeService from '../../../services/ChromeService';
export default class RestockMonitor {
constructor(intervalMs) {
this.intervalMs = intervalMs;
this.onNewProductsCallbacks = [];
this.onProductsRestockCallbacks = [];
}
<button id="elem" onclick="alert('Click!');">Autoclick</button>
<script>
let event = new Event("click");
elem.dispatchEvent(event);
</script>
<h1 id="elem">Hello from the script!</h1>
<script>
https://a.jd.com//ajax/queryServerData.html
{"api":"mtop.common.getTimestamp","v":"*","ret":["SUCCESS::接口调用成功"],"data":{"t":"1586519130440"}}
http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp
2.苏宁时间服务器接口api:
http://quan.suning.com/getSysTime.do
const users = JSON.parse(
fs.readFileSync(`${__dirname}/_data/users.json`, 'utf-8')
)
var mySchema = new Schema({
name: {
type: String
},
createdAt: {
type: Date,
default: Date.now
}
});
@codeyourwayup
codeyourwayup / uniqueCaseInsensitive
Created August 19, 2020 05:56
channelName: { type: String, required: [true, 'Please add a channel name'], unique: true, uniqueCaseInsensitive: true },
const crypto = require('crypto')
const mongoose = require('mongoose')
const bcrypt = require('bcryptjs')
const jwt = require('jsonwebtoken')
const uniqueValidator = require('mongoose-unique-validator')
const Schema = mongoose.Schema
const UserSchema = new Schema(
const objectToQueryString = queryParameters => {
return queryParameters
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
const symbol = queryString.length === 0 ? '?' : '&';
queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';
return queryString;
}, '')
: '';
};
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};