Skip to content

Instantly share code, notes, and snippets.

@shaykav
shaykav / tictactoe.rb
Created October 31, 2017 05:36
repl game week 1
board = {
"1": " ",
"2": " ",
"3": " ",
"4": " ",
"5": " ",
"6": " ",
"7": " ",
"8": " ",
"9": " "
@shaykav
shaykav / the_taquiza_experience.rb
Created November 6, 2017 06:13
command line waiter
taquiza_menu = {
:name => "Taquiza",
:sections => [
{
:name => "Tacos",
:description => "Freshly made blue corn tortillas",
:items => [
{
:name => "Al Pastor",
:description => "pork, achiote, pineapple",
@shaykav
shaykav / filter_methods.rb
Created December 7, 2017 05:32
Filter activity refactoring a controller by using before/after actions
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
after_action :slack_notif, only: [:create, :update, :destroy]
def index
@users = User.all
end
def show
end
@shaykav
shaykav / ws-handler6.ts
Last active March 25, 2021 22:21
Handler for disconnect event type
if (eventType === 'DISCONNECT') {
// Get all subscribers
const subscriptions = mapper.query(Subscription, {
connectionId: equals(connectionId)
});
// Remove subscriptions
for await (const subscription of subscriptions) {
const sub = Object.assign(new Subscription(), {
id: `${connectionId}|${subscription.subscription.id}`
});
@shaykav
shaykav / ws-handler4.ts
Last active March 25, 2021 22:19
Handler for connect event type
if (eventType === 'CONNECT') {
return {
statusCode: 200,
headers: {
'Sec-WebSocket-Protocol': 'graphql-transport-ws'
},
body: ''
};
}
export const handler: Handler<APIGatewayEvent> = async (event, context, callback) => {
if (!event.requestContext) {
return {
statusCode: 500,
body: ''
};
}
const { eventType, connectionId } = event.requestContext;
import React, { FC } from 'react';
import { ApolloProvider } from '@apollo/react-hooks';
import {
InMemoryCache,
ApolloClient,
HttpLink,
split,
} from 'apollo-boost';
// WS link from example here - https://github.com/enisdenjo/graphql-ws#apollo-client
import { ApiGatewayManagementApi } from 'aws-sdk';
export const createGateway = (requestContext: any) =>
new ApiGatewayManagementApi({
apiVersion: 'latest',
endpoint: `https://${requestContext.apiId}
.execute-api.us-east-1.amazonaws.com/${requestContext.stage}`
});
resources:
Resources:
connectionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: CONNECTION_TABLE
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema: