Skip to content

Instantly share code, notes, and snippets.

@scf4
scf4 / app.js
Last active February 1, 2024 23:58
react native selectively highlight input text (mentions)
import React from 'react';
import { View, Text, TextInput, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
wrapper: {
width: '90%',
height: 24,
position: 'relative',
alignSelf: 'center',
},
const { types, Client, Pool } = require('pg');
const Knex = require('knex');
const knex = new Knex({
client: 'pg',
connection: 'postgresql://localhost/postgres',
});
const benchmark = async (fn, num) => {
const start = new Date().getTime();
@scf4
scf4 / index.js
Created July 5, 2017 19:30
[Draft.js plugins] How to force block style on first line for a heading/title like Medium
// Import and add to your Editor's plugins
import { RichUtils } from 'draft-js';
const HEADING = 'header-one';
export default () => ({
onChange: (editorState) => {
const currentContent = editorState.getCurrentContent();
const firstBlockKey = currentContent.getBlockMap().first().getKey();
@scf4
scf4 / app.js
Last active February 5, 2018 23:03
graphql koa app.js with http and ws endpoints
/* eslint-disable no-console */
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import cors from 'kcors';
import { SubscriptionServer as WebSocketServer } from 'subscriptions-transport-ws';
import { execute, subscribe } from 'graphql';
import { graphqlKoa, graphiqlKoa as graphiqal } from 'graphql-server-koa';
import { formatError, isInstance } from 'apollo-errors';
export default async (knex) => {
const foreignKeys = await knex('pg_constraint')
.select('*')
.where('contype', '=', 'f');
const queries = foreignKeys.map(async foreignKey => {
const [keyData] = await knex('pg_class')
.select('relname')
.where('oid', '=', foreignKey.conrelid);