Skip to content

Instantly share code, notes, and snippets.

View devmnj's full-sized avatar
💭
Exploring Algos

Manoj AP devmnj

💭
Exploring Algos
View GitHub Profile
@devmnj
devmnj / nuxt-config.js
Created July 26, 2021 16:00
Prisma Nuxtjs API using Middleware
import colors from 'vuetify/es5/util/colors'
export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
ssr: false,
serverMiddleware:[
'~/api/index.ts',
] ,
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
@devmnj
devmnj / gqlClient.js
Created September 19, 2021 13:09
Graphql client for React and Keystone5 CMS - using the fetch API
function gqlClient(query, variables = {}) {
return fetch("http://localhost:3000/admin/api", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
variables,
query,
@devmnj
devmnj / App.config
Created October 3, 2021 15:15
DotNet connection string fot SQL Server
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Dolphin_Accounts.Properties.Settings.sql_connection"
connectionString="Data Source=.\sqlexpress;Initial Catalog=dolphine;User ID=sa;Password=" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
@devmnj
devmnj / case-when.sql
Created October 3, 2021 15:20
SQL Case... when example
SELECT invoice ,
case
when isnull(sum(tr.cramount),0)>isnull(sum(tr.dramount),0) then isnull(sum(tr.cramount),0)-isnull(sum(tr.dramount),0)
else 0
end as cr,
case
when isnull(sum(tr.dramount),0)>isnull(sum(tr.cramount),0) then isnull(sum(tr.dramount),0)-isnull(sum(tr.cramount),0)
else 0
end as dr
@devmnj
devmnj / slices.js
Created October 9, 2021 02:26
Prismic - React slice rendering component
class Slices extends React.Component {
render() {
if (this.props.slices) {
const pageContent = this.props.slices.map((slice, index) => {
if (slice.slice_type === "heading_slice") {
console.log('heading');
return (
@devmnj
devmnj / fetcher.ts
Created October 13, 2021 04:39
Type Script Fetcher (API) for SWR
export default async function fetcher<JSON = any>(
input: RequestInfo,
init?: RequestInit
): Promise<JSON> {
const res = await fetch(input, init)
return res.json()
}
@devmnj
devmnj / swr.ts
Created October 13, 2021 04:42
Vercer useSWR example
function Profile () {
const { data, error } = useSWR('/api/user/123', fetcher)
if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
// render data
return <div>hello {data.name}!</div>
}
@devmnj
devmnj / fetcher.js
Created October 13, 2021 04:43
Fetcher for SWR - React
export const fetcher = (...args) => fetch(...args).then(res => res.json())
@devmnj
devmnj / implementuseForm.js
Created October 25, 2021 15:39
React Custom Hook for data validation
export default function SignUp() {
const { errors, values, handleChange, handleSubmit } = useForm(() => {
console.log('No errors found')
console.log('Can implement mutation here')
}, Validate)
return (
<form ...>)
}
@devmnj
devmnj / hook.js
Created November 4, 2021 13:49
React local Storage hook
import React from "react";
const useLocalStorage=(key, initialValue,clearCache=false)=> {
// State to store our value
// Pass initial state function to useState so logic is only executed once
if(clearCache){window.localStorage.removeItem(key)}
const [storedValue, setStoredValue] = React.useState(() => {
try {
// Get from local storage by key
const item = window.localStorage.getItem(key);