Skip to content

Instantly share code, notes, and snippets.

View pantharshit00's full-sized avatar
🙃

Harshit Pant pantharshit00

🙃
View GitHub Profile
@pantharshit00
pantharshit00 / main.ts
Created December 23, 2021 18:37
Prisma middleware example
import { PrismaClient } from "@prisma/client";
import slugify from "slugify";
async function main() {
const prisma = new PrismaClient();
prisma.$use(async (params, next) => {
// Manipulate params here
if (params.model == "Project" && params.action == "create") {
params.args.data.slug = slugify(params.args.data.name);

Keybase proof

I hereby claim:

  • I am pantharshit00 on github.
  • I am pantharshit00 (https://keybase.io/pantharshit00) on keybase.
  • I have a public key ASCKJQBTqUkSNmSY6mM8omII1h3s1ci1YR8cTH5yav42Cwo

To claim this, I am signing this object:

@pantharshit00
pantharshit00 / app.js
Last active August 22, 2021 21:20
Simple express app using JWT authentication
/**
* To get started install
* express bodyparser jsonwebtoken express-jwt
* via npm
* command :-
* npm install express body-parser jsonwebtoken express-jwt --save
*/
// Bringing all the dependencies in
const express = require('express');
import express from 'express';
import {renderToString} from 'react-dom/server';
import React from 'react';
import Component from './react-router.jsx';
import {StaticRouter as Router} from 'react-router-dom';
const app = express();
function template(data){
return `
@pantharshit00
pantharshit00 / package.json
Created March 29, 2017 10:14
Packages for sequelize project
{
"name": "testPassport",
"version": "1.0.0",
"description": "Simple auth app",
"main": "app.js",
"author": "Harshit Pant",
"license": "MIT",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
@pantharshit00
pantharshit00 / app.js
Created March 29, 2017 10:13
Server for passport sequelize
// Using express as a server
const express = require('express');
const morgan = require('morgan'); // JUST FOR LOGS
const session = require('express-session') // for sessions
const bodyParser = require('body-parser') // for req.body
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const User = require('<relative path to User.js eg ./User>') // Use relative path to the User file
@pantharshit00
pantharshit00 / User.js
Created March 29, 2017 10:11
Sample sequelize model
const Sequelize = require('sequelize');
const connection = new Sequelize('<db name here>','<db username here>','<db passworfd here>',{ // Defining our connect by Sequelize constructor
host: '<db host here eg localhost, db.example.com, 127.0.0.1 >',
dialect: 'postgres' // According to which dbms you are using
})
const User = connection.define('users',{
id:{
type: Sequelize.INTEGER, // All dataTypes format available here http://bit.ly/2ofwgAm
@pantharshit00
pantharshit00 / react-router.jsx
Last active April 13, 2017 08:41
React Router v4
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router,Link,Route} from 'react-router-dom';
export default class App extends React.Component{
render(){
return(
<Router>
<div>
<ul>