Skip to content

Instantly share code, notes, and snippets.

View pancakeswap-tokenprice.js
import Web3 from 'web3';
import { Fetcher, ChainId, Token } from '@pancakeswap/sdk';
import { JsonRpcProvider } from '@ethersproject/providers';
import { BNB_ADDRESS, MAINNET_URL } from '../constants';
const provider = new JsonRpcProvider('https://bsc-dataseed1.binance.org/');
class Web3Service {
constructor() {
this.web3 = new Web3(MAINNET_URL);
View rollup.config.js
import vue from "rollup-plugin-vue";
import typescript from "rollup-plugin-typescript2";
import commonjs from "rollup-plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import postcss from "rollup-plugin-postcss";
import vueGbsModule from "./prefix.plugin";
import postcssImport from "postcss-import";
import tailwind from "tailwindcss";
import purgecss from "@fullhuman/postcss-purgecss";
import prefixer from "postcss-prefixer";
View sequelize-tags-taxes.js
const includeTags = (ids) => `exists (
select *
from jobtag jt
where jt.job_id = job.id
and shop_tag_id in (${ids})
group by job_id
having count(*) >= ${ids.length}
)`;
const excludeTags = (ids) => `not exists(
View data.controller.js
await consumer.update({
phone_id: consumer.phones?.[0]?.id,
email_id: consumer.emails?.[0]?.id,
full_name_id: consumer.names?.[0]?.id,
g_address_id: consumer.addresses?.[0]?.id,
});
View react-apollo-cache-example-4.js
const TaskDetails = ({ id }) => {
const [updateTask] = useMutation(UPDATE_TASK);
const { data = {} } = useQuery(GET_TASK, { variables: { id } });
const { task = { comments: [] } }: { task: ITask } = data;
const onUpdate = (key) => (value) => {
const task = { [key]: value };
updateTask({
variables: { task, id },
update: (proxy, { data = {} }) => {
View react-apollo-cache-example-3.js
const onUpdate = (key) => (value) => {
const task = { [key]: value };
updateTask({
variables: { task, id },
update: (proxy, { data = {} }) => {
// update cache with local values
proxy.writeData({ id: `Task:${id}`, data: task });
// or update cache with the values coming from the server,
// for example if you need to reflect the updated timestamp
View react-apollo-cache-example-1.js
const TaskDetails = ({ id }) => {
const [updateTask] = useMutation(UPDATE_TASK);
const { data = {} } = useQuery(GET_TASK, { variables: { id } });
const { task = { comments: [] } }: { task: ITask } = data;
const onUpdate = (key) => (value) => {
updateTask({ variables: { task: { [key]: value }, id } });
};
return (
<div>
<Typography.Text strong editable={{ onChange: onUpdate('name') }}>
View react-apollo-cache-example-2.js
const [updateTask] = useMutation(UPDATE_TASK, {
refetchQueries: ['getTask', 'getTasks'],
});
View LocationIcon.vue
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="28"
height="28"
viewBox="0 0 28 28"
>
<defs>
<circle id="my-location-a" cx="330" cy="366" r="8" />
@david-mart
david-mart / icon-url-generator.js
Last active May 23, 2020
icon-url-generator.js
View icon-url-generator.js
import Vue from 'vue'
import LocationIcon from './LocationIcon'
// create a constructor from a Vue component
const LocationIconConstructor = Vue.extend(LocationIcon)
export const getColoredIconUrl = (fillColor, strokeColor) => {
// create a Vue element with required props
const iconComponent = new LocationIconConstructor({ propsData: { fillColor, strokeColor } })
// mount the component shadow DOM