Skip to content

Instantly share code, notes, and snippets.

View bs1180's full-sized avatar

Ben Smith bs1180

  • Vienna, Austria
View GitHub Profile
@bs1180
bs1180 / gist:3eb4aa5c48e179cc28a5d316dac9aed4
Created August 10, 2021 05:23
Playwright fixture - start server
import { createServer, Server } from 'http';
import { test as base } from '@playwright/test';
import path from 'path';
import serve from 'serve-handler';
type StaticWorkerFixtures = {
port: number;
server: Server;
};
@bs1180
bs1180 / __main__.js
Created July 7, 2018 14:19
This runs as a stdlib.com serverless function (built with the code.xyz IDE)
const axios = require("axios");
const R = require("ramda");
module.exports = async (latitude = 0, longitude = 0) => {
const { data } = await axios.get("https://api.foursquare.com/v2/venues/explore", {
params: {
client_id: process.env.FOURSQUARE_CLIENT_ID,
client_secret: process.env.FOURSQUARE_CLIENT_SECRET,
v: 20180707,
section: "coffee",
@bs1180
bs1180 / apollo.js
Created January 2, 2017 11:16
Apollo HOC component
import 'isomorphic-fetch'
import { getDataFromTree, ApolloProvider } from 'react-apollo/lib/index'
import { ApolloClient, createNetworkInterface } from 'apollo-client'
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { omit } from 'lodash'
const isServer = (typeof window === 'undefined')
const makeClient = () => new ApolloClient({
ssrMode: true,
@bs1180
bs1180 / example.md
Created September 15, 2016 18:56
Apollo server schema definitions

By

user.js

const type = `
  type User {
    id: Int!
    email: String
    courses: [Course]
 }
@bs1180
bs1180 / snippet.js
Created April 19, 2016 14:53
Current method of signing S3 upload URL
// tools.generateId
function generateId(size){
var text = [];
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < size; i++ )
text.push(possible.charAt(Math.floor(Math.random() * possible.length)));
return text.join('');
}
@bs1180
bs1180 / list.js
Last active April 17, 2016 18:51
List Component
import React, { Component, PropTypes } from 'react'
import {dataConnect} from 'relate-js';
import { Link } from 'react-router'
const data = (
null,
null,
(props) => ({
fragments: {
viewer: {
@bs1180
bs1180 / gist:13d40a96c2f7c3c9848b
Created March 13, 2016 09:55
How to get an array of requested field names from graphQL query
import { simplifyAST } from 'graphql-sequelize'
const parseFields = (ast) => {
let s = simplifyAST(ast[0])
return Object.keys(s.fields)
}
// and then in use:
accounts: {
type: new GraphQLList(accountType),
// define libraries you would need
var oauth = require('oauth')
var AWS = require('aws-sdk')
var cuid = require('cuid')
// define your OAuth-application credentials
var twitterConsumerKey = 'xxxxxxxxxxxxxxxxxxxx'
var twitterConsumerSecret = 'xxxxxxxxxxxxxxxxxxxx'
// ensure AWS is requesting the nearest region
@bs1180
bs1180 / accounting.sql
Created January 21, 2016 08:41 — forked from NYKevin/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@bs1180
bs1180 / form.js
Last active September 4, 2015 14:02
Dynamic forms in redux-form
export default class FormWrapper {
render () {
const Form = makeForm(['name', 'age', 'sex']);
return (
<div>
<Form />
</div>