Skip to content

Instantly share code, notes, and snippets.

var $window = $(window),
lastScrollTop = 0;
function onScroll (e) {
var top = $window.scrollTop();
if (lastScrollTop > top) {
console.log('top');
} else if (lastScrollTop < top) {
console.log('down');
}
@StrongerMyself
StrongerMyself / SwipeDetect.d.ts
Last active July 5, 2019 06:40
detect touch swipe (none, left, right, up, down)
export type SwipeDirect = ('none' | 'left' | 'right' | 'up' | 'down')
export interface ISwipeDetect {
direct: SwipeDirect
offsetDist: number
startX: number
startY: number
distX: number
distY: number
init: () => void
@StrongerMyself
StrongerMyself / javascriptreact.json
Created February 25, 2019 09:32
vs-code jsx snippets
{
"jsx-component": {
"prefix": "jsx-component",
"body": [
"import React, { Component } from 'react'",
"import PropTypes from 'prop-types'",
"",
"import c from './${2:style}.style.sass'",
"",
"export default class ${1:component} extends Component {",
@StrongerMyself
StrongerMyself / typescriptreact.json
Last active November 16, 2020 12:23
vs-code tsx snippets
{
"tsx-test-filename": {
"prefix": "tsx-test-filename",
"body": [
"${TM_FILENAME_BASE/^(.)|([.-](.))/${1:/upcase}${3:/upcase}/g}",
],
"description": "TSX filename"
},
"tsx": {
@StrongerMyself
StrongerMyself / store.js
Last active July 18, 2019 04:29
Observer Store
export const deepCopy = (data) => {
return typeof data === 'object' ? (
JSON.parse(JSON.stringify(data))
) : (
data
)
}
export function Store(_init) {
let init = deepCopy(_init)
@StrongerMyself
StrongerMyself / graphql.client.js
Created June 18, 2019 12:12
Idea graphql client API
var api = new GraphQL(path, {
method: 'POST', // POST by default.
headers: {
'Access-Token': 'some-access-token'
},
query: {
tags: 'tags { ...tag }',
tag: 'tag { ...tag }',
},
mutation: {
@StrongerMyself
StrongerMyself / dotobj.js
Last active September 6, 2019 09:21
dotobj
const pathToRoute = (path = '') => {
return path.split('.').map(key => `['${key}']`).join('')
}
const onGet = (path = '') => {
return new Function('obj', `return obj${pathToRoute(path)}`)
}
const onSet = (path = '') => {
return new Function('obj', 'val', `obj${pathToRoute(path)} = val; return obj`)
@StrongerMyself
StrongerMyself / schemaRelBySpec.ts
Last active July 5, 2019 07:08
Graphql parser AST query for optimal ORM query. Get relation map by spec relation list.
import { GraphQLResolveInfo } from 'graphql'
const unique = (arr = []) => {
let obj = {}
for (let i = 0;i < arr.length;i++) {
let str = arr[i]
if (!!str) obj[str] = true
}
return Object.keys(obj)
}
@StrongerMyself
StrongerMyself / line-chart.js
Created August 20, 2019 14:08
d3-v5-line-chart
import * as d3 from 'd3'
import c from '../styles.css'
const svg = d3.select('svg')
const margin = { top: 20, right: 20, bottom: 110, left: 40 }
const width = +svg.attr('width') - margin.left - margin.right
const height = +svg.attr('height') - margin.top - margin.bottom
const margin2 = { top: 430, right: 20, bottom: 30, left: 40 }
const height2 = +svg.attr('height') - margin2.top - margin2.bottom
const http = require('http');
const httpProxy = require('http-proxy');
const options = {
changeOrigin: true,
protocol: 'https',
target: 'https://yobit.net',
host: 'yobit.net',
};