Skip to content

Instantly share code, notes, and snippets.

View john-osullivan's full-sized avatar
Focusing

John O'Sullivan john-osullivan

Focusing
View GitHub Profile
@john-osullivan
john-osullivan / easy-imports.ts
Last active September 17, 2019 02:04
Dev Diaries #2 - Module layout for easy imports
// The type reference is so wordy! This isn't convenient.
import Types from '@eximchain/dappbot-types';
const args: Types.Methods.Auth.Login.Args = { ... };
// We can make the reference more compact by importing a
// more specific slice of the overall types.
import Auth from '@eximchain/dappbot-types/spec/methods';
const args: Auth.Login.Args = { ... };
@john-osullivan
john-osullivan / sample-validator-naming.ts
Last active September 16, 2019 21:03
Dev Diaries #2 - Types Naming Convention
export interface SomeData {
foo: string
bar: string
}
export function newSomeData(): SomeData {
return {
foo: 'example',
bar: 'object'
}
@john-osullivan
john-osullivan / sample-login-call.ts
Created September 16, 2019 20:27
Using Login namespace
import { Login } from '@eximchain/dappbot-types/spec/methods/auth';
import request from 'request-promise-native';
const baseApiUrl = 'https://api.dapp.bot';
async function loginToDappbot(creds:Login.Args):Login.Result {
const res:Login.Response = await request({
headers : { 'Content-Type' : 'application/json' },
method : Login.HTTP,
@john-osullivan
john-osullivan / auth.ts
Last active September 16, 2019 20:30
Dev Diaries #2 - Example API namespace
import { XOR } from 'ts-xor';
import { ApiResponse } from '../../responses';
export namespace Login {
export const HTTP:HttpMethods.POST = 'POST';
export const Path = `${authBasePath}/${ResourcePaths.login}`
export interface Args {
username: string,
@john-osullivan
john-osullivan / using-stripe-types.ts
Created September 16, 2019 19:33
Dev Diaries #2 - StripeTypes Import
import API from '@eximchain/dappbot-api-client';
import Payment, { StripeTypes } from '@eximchain/dappbot-types/spec/methods/payment';
// Nested namespaces make for legible collision-free names
const res:Payment.Read.Response = await API.payment.read.call();
// Helper namespace cuts down on extra text
const subscription:StripeTypes.Subscription = res.data.subscription;
@john-osullivan
john-osullivan / sample-payment-type.ts
Created September 16, 2019 19:12
Dev Daries #2 - Example namespace of types from Stripe
import AllStripeTypes from 'stripe';
export namespace StripeTypes {
export type Customer = AllStripeTypes.customers.ICustomer;
export type Card = AllStripeTypes.ICard;
export type Subscription = AllStripeTypes.subscriptions.ISubscription;
export type SubscriptionState = AllStripeTypes.subscriptions.SubscriptionStatus;
export type Invoice = AllStripeTypes.invoices.IInvoice;
@john-osullivan
john-osullivan / LoginScreen.tsx
Last active September 16, 2019 18:00
Dev Diaries #2 - Type Factory in useState
export function LoginScreen(props) {
const [loginArgs, setLoginArgs] = React.useState(Login.newArgs());
async function submitLogin() {
const res:Login.Response = await DappbotAPI.auth.login.call(loginArgs);
...
}
return (
...
@john-osullivan
john-osullivan / isSuccessResponse.ts
Last active September 16, 2019 16:53
Dev Diaries #2 - Sample Type Guard
/**
* Type guard; only returns `true` if object shape has a non-null
* `data` value and `err` has a null value.
* @param val
*/
export function isSuccessResponse(val:any): val is SuccessResponse {
return (
isObject(val) &&
val.data &&
val.err === null
@john-osullivan
john-osullivan / gist:7947988
Created December 13, 2013 17:32
Paragraph quoting Alexis Ohanian for "An Analysis of reddit as an Online Community Platform" term paper.
All of this evidence demonstrates that reddit the company seems like a welcoming community, but the key to their success lies in
how reddit the website is good at developing the feeling of community. This is achieved by the subreddit system, which lets any
user create a new subreddit for users to submit links to. Two months into the founding of reddit, the two co-founders, Alexis
Ohanian and Steve Huffman, had an argument over how to let people categorize their submissions to reddit.com. Their two
candidates were searchable tags, which were very popular athte time, and subreddits, a system where users could make their own
subsections of the site to submit to. The concept which Huffman said to Ohanian to explain the purpose of subreddits was:
Let’s say somebody submits a story about how the Nets aren’t doing well and we’re using the tag system. “Nets not performing up
to pre-season expectations this year. #Nets #Brooklyn #NYC #NBA” The problem is that each of those groups could have a
completely differe