Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@parris
parris / Login.js
Last active January 15, 2018 23:55
Fervor + PostgraphQL/Postgraphile + Knex Authentication Example
// src/apps/Login.js
import { React, Form, clientCookies, gql } from 'fervor/lib';
import Template from '../components/Template';
import styles from './styles/about.scss';
const authenticate = gql`
mutation Authenticate($login: AuthenticateInput!) {
authenticate(input: $login) {
jwtToken
@postspectacular
postspectacular / 00-sigmoid-approx.ts
Last active November 2, 2019 20:31
Sigmoid versions (AssemblyScript)
// uses Math.exp() approximation from:
// https://www.musicdsp.org/en/latest/Other/222-fast-exp-approximations.html
// @ts-ignore: decorator
@inline
function fastexp9(x: f64): f64 {
// prettier-ignore
return (362880+x*(362880+x*(181440+x*(60480+x*(15120+x*(3024+x*(504+x*(72+x*(9+x)))))))))*2.75573192e-6;
}

The following sets up a local k3d cluster and deploys Postgres and Hasura GraphQL Engine.

NOTE: All data will be lost when containers restart

# Create the cluster mapping NodePorts to Host ports and set KUBECONFIG
k3d create --publish 5432:30032 --publish 8080:30080 --workers 2
export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')"

# Deploy postgres
@lhorie
lhorie / write-better-tests.md
Last active June 12, 2020 12:59
Write better tests with one neat trick

Write better tests with one neat trick

TL:DR; assert your input

If you write non-trivial code, inevitably you'll run into a situation where setting up a test is not super readable. Maybe you have to mock a bunch of things, or the input data is a data structure that spans dozens of LOC, or maybe you are testing with a large-ish fixture that was defined in another file because linting or whatever.

Due to the nature of my job, I happen to read a lot of other people's code, so you can imagine how mildly annoying it is when I'm code reviewing something, and the test looks something like this:

test('codemod does what it needs to', async () => {
@baohouse
baohouse / GraphiQLExplorer.tsx
Last active January 21, 2021 22:08
Fork of graphiql-explorer 0.4.5 to support list types and object-based custom args
/**
* Copied from https://github.com/OneGraph/graphiql-explorer (0.4.5)
* We fork because we need to support customizable fields and could not wait for
* the PR process to finish. Also converted Flow type to TypeScript.
*/
import { Tooltip } from 'antd';
import prettier from 'prettier/standalone';
import parserGraphql from 'prettier/parser-graphql';
import React, { Fragment } from 'react';
@ess7
ess7 / jsfx_dotprod.c
Created October 16, 2018 04:30
JSFX extension: dot product
// params: y0, y1, interleaved x, coeff, n
static EEL_F NSEEL_CGEN_CALL dotprod2(void *opaque, INT_PTR np, EEL_F **parms) {
EEL_F **blocks = (EEL_F **)opaque;
int xofs = *parms[2];
int cofs = *parms[3];
int n = *parms[4];
*parms[0] = 0.0;
*parms[1] = 0.0;
if (unlikely(n <= 0 || xofs < 0 || cofs < 0 ||
@blister
blister / gist:740829
Created December 14, 2010 18:19
Bash script to add a delay to the localhost interface on Linux machines
#!/bin/bash
# Copyright 2010 Eric Ryan Harrison <me@ericharrison.info>
# Inspired by:
# http://daniel.haxx.se/blog/2010/12/14/add-latency-to-localhost/
if [ -n "$1" ]
then
if [ "$1" = "off" ]
then
tc qdisc del dev lo root
@ess7
ess7 / myadd.cpp
Last active November 6, 2021 20:19
Call C function from Reaper JSFX (x86/x64, no hardcoded offsets, 6.x tested)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <reaper_plugin.h>
#include <ns-eel.h>
/*
* If you actually try this, the JS effect that uses the new function should not be the first one loaded,
* otherwise you will get an "undefined 'myadd'" error.
* Workarounds: recompile/reset or add any JS effect before this
{
"problemMatcher": [
{
"owner": "hlint",
"severity": "warning",
"pattern": [
{
"regexp": "^([^:]*\\/)([^:/]*):(\\d+)(-\\d+)?:(\\d+)(-\\d+)?: (Warning|Error): (.*)$",
"fromPath": 1,
"file": 2,