Skip to content

Instantly share code, notes, and snippets.

David Konsumer konsumer

View GitHub Profile
View knexFromUrl.js
const parseDbUrl = require('parse-database-url')
const isString = require('is-string')
const isNumber = require('is-number')
const unflatten = require('unflatten')
const parseBoolean = (string, defaultValue = null) => {
// handle numbers
if (isNumber(string)) {
return parseFloat(string) > 0
}
@konsumer
konsumer / parseBoolean.js
Created Apr 11, 2019
Similar to parse-boolean, to turn a string into a boolean, but it permits numbers, actual booleans, number-strings, and yes|no|true|false strings (case-insensitive, even with padding.)
View parseBoolean.js
const isString = require('is-string')
const isNumber = require('is-number')
const parseBoolean = (string, defaultValue = null) => {
// handle booleans & numbers
if (!isString(string)) {
return !!string
}
// handle numbers/number-strings
View test.js
const { parse } = require('url')
const { decode } = require('querystring')
const { unflatten } = require('flat')
const dbUriParse = (url) => {
let options = { connection: {} }
const u = parse(url)
const { protocol, pathname, hostname, auth, query, port } = u
options.client = protocol.replace(':', '')
View gist:8d14d527497a8c83ce4dc7d3fece4da5
./node_modules/.bin/now dev
> Ready! Development server running at http://localhost:3000
> Running initial builds
downloading user files...
installing dependencies for user's code...
installing to /home/konsumer/.cache/co.zeit.now/dev/workPaths/27666009/user/node-server
yarn install v1.15.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
View gist:3d3ffd460c242481c78554580387e285
./node_modules/.bin/now dev
> Ready! Development server running at http://localhost:3000
> Running initial builds
downloading user files...
installing dependencies for user's code...
installing to /Users/konsumer/Library/Caches/co.zeit.now/dev/workPaths/52020331/user/node-server
yarn install v1.13.0
info No lockfile found.
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
View App.js
import React from 'react'
import { Box } from 'ink'
import Gradient from 'ink-gradient'
import BigText from 'ink-big-text'
import { useCounter, useStdout } from './hooks'
const App = () => {
const [counter] = useCounter()
const stdout = useStdout()
View dmeo3.js
import React, { useState, useEffect } from 'react'
import { render, Box } from 'ink'
import Gradient from 'ink-gradient'
import BigText from 'ink-big-text'
import size from 'window-size'
const useCounter = () => {
const [counter, setCounter] = useState(0)
let i
useEffect(() => {
View demo2.js
import React, { useState, useEffect } from 'react'
import { render, Box } from 'ink'
import Gradient from 'ink-gradient'
import BigText from 'ink-big-text'
const useCounter = () => {
const [counter, setCounter] = useState(0)
let i
useEffect(() => {
i = setInterval(() => {
View counter.js
import React, { useState, useEffect } from 'react'
import { render } from 'ink'
import Gradient from 'ink-gradient'
import BigText from 'ink-big-text'
const useCounter = () => {
const [counter, setCounter] = useState(0)
let i
useEffect(() => {
i = setInterval(() => {
@konsumer
konsumer / serial_promise_glob_require.js
Created Feb 19, 2019
Require each file in a directory, and wait for it's `_setup` function to complete
View serial_promise_glob_require.js
const reqGlob = require('require-glob')
const run = async () => {
const resolvers = await reqGlob('./resolvers/**/*.js')
await Object.values(resolvers).reduce(
(p, r) => p.then(() => r._setup && r._setup()),
Promise.resolve()
)
}
You can’t perform that action at this time.