Skip to content

Instantly share code, notes, and snippets.

View Necmttn's full-sized avatar
🖖
Maker

Neco Necmttn

🖖
Maker
View GitHub Profile
@Necmttn
Necmttn / turnJSONSchemaToZodSchema.ts
Created September 10, 2023 05:27
turnJSONSchemaToZodSchema.ts
import * as z from "zod";
/**
* This function converts a JSON schema into a Zod schema.
*
* @param schema The JSON schema to be converted. The schema should follow the JSON Schema Draft 7 specification.
*
* Example:
* schema: {
* $schema: "http://json-schema.org/draft-07/schema#",
* title: "Complex Example",
@Necmttn
Necmttn / executer.stream.ts
Created August 30, 2023 11:14
Stream execute openai call including the JSON responses.
import {
createParser,
ParsedEvent,
ReconnectInterval,
} from "eventsource-parser";
import { Procedure } from "./procedure";
import openai, { ChatCompletionRequestMessage } from "@acme/openai";
import _ from "lodash";
export type Message = Omit<ChatCompletionRequestMessage, "role"> & {
@Necmttn
Necmttn / filterGenerator.ts
Created December 20, 2021 08:35
Attempt to making filter generation automated in Anchor / Solana.
export const generateFilter = (filterParams) => {
const IDL_DEFINATION = {
name: "vote",
type: {
kind: "struct",
fields: [
{
name: "proposalId",
type: "u64",
},
@Necmttn
Necmttn / compare sql tables
Created August 13, 2021 19:45
compare_sql_tables.js
const createDisctionaryOfColumns = (tableDefination) => {
return tableDefination.split(',').reduce((prev,column) => {
const part = column.trim().split(/\s+/);
console.log(part)
const cName = part[0];
const type = part[1];
prev[cName]= type;
return prev;
}, {})
}
@Necmttn
Necmttn / action.js
Created February 14, 2019 03:03
Better way of making Redux Ajax actions.
const REQUEST = 'REQUEST'
const SUCCESS = 'SUCCESS'
const FAILURE = 'FAILURE'
function action(type, payload = {}) {
return {type, ...payload}
}
const listJDs = {
request: () => action(ActionTypes.LIST_JDS[REQUEST]),
@Necmttn
Necmttn / logger.js
Created February 13, 2019 06:43
Better CloudWatch Logs.
const winston = require('winston');
const logger = winston.createLogger({
level: 'debug',
// (typeof(process.env.NODE_ENV) === 'string' && process.env.NODE_ENV.startsWith('prod'))
// ? 'info'
// : 'debug',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.splat(),
import React from 'react';
import { Form, Input, Button, Col, Icon } from 'antd';
import { Logger } from 'aws-amplify';
import { intlShape, injectIntl } from 'react-intl';
import styled from 'styled-components';
import * as t from '../../i18n';
const logger = new Logger('Form:Login', 'DEBUG');
@Necmttn
Necmttn / login.js
Last active November 28, 2018 10:52
import React from 'react';
import { Button, Icon, message } from 'antd';
import { navigateTo } from 'gatsby-link';
import { Auth, Logger } from 'aws-amplify';
import { LoginForm } from '../../Form'
const logger = new Logger('Auth:Login');
class Login extends React.Component {
state = { status: 'idle' }
import Amplify, { Auth } from 'aws-amplify';
import { withAuthenticator } from 'aws-amplify-react/dist/Auth';
import AWSAppSyncClient from 'aws-appsync';
import { ApolloProvider } from 'react-apollo';
const client = new AWSAppSyncClient({
url: 'https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql',
region: 'us-east-1',
auth: {
// AWS Cognito User Pool
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
const GET_JOB = gql`
 query GetJobById($Id: String!) {
 Job(Id: $Id) {
 images {
 url
 id
 }
 isLiked @client
 }
 }