Skip to content

Instantly share code, notes, and snippets.

View foyzulkarim's full-sized avatar
🚀
building awesome stuffs

Foyzul Karim foyzulkarim

🚀
building awesome stuffs
View GitHub Profile
@foyzulkarim
foyzulkarim / usages.js
Created March 3, 2024 12:10
Simplify Express.js Validation: Sync Joi and Mongoose Schemas
const viewModelProps = {
title: { type: String, isRequired: true, minLength: 5, unique: true, index: true },
category: { type: String, isRequired: true },
}
// in mongoose
const videoSchema = new mongoose.Schema({
...generateSchema(true, viewModelProps),
duration: {
type: Number,
@foyzulkarim
foyzulkarim / index.js
Created July 14, 2021 15:55
Webinar on Node.js : Express.js handle 200K+ request in 10seconds using Cluster and PM2
const express = require('express')
var numCPUs = require('os').cpus().length;
const cluster = require('cluster');
const app = express()
app.get('/', (req, res) => {
res.send('Hello World!')
});
@foyzulkarim
foyzulkarim / App.config.ts
Created June 18, 2017 16:41
Sample Angular UI Router configuration in typescript
module App {
"use strict";
export class AppConfig {
static $inject = ["$stateProvider", "$urlRouterProvider", "localStorageServiceProvider"];
constructor($stateProvider: angular.ui.IStateProvider,
$urlRouterProvider: angular.ui.IUrlRouterProvider,
localStorageProvider: angular.local.storage.ILocalStorageServiceProvider
@foyzulkarim
foyzulkarim / AzureSigninFunction.cs
Created April 20, 2018 10:50
Azure Function is used here as ASP.NET Identity Token provider for SPA Applications. Then this token will be used for other secured API calls, eg. saving a Sale entity to database
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace FunctionApp1
{
@foyzulkarim
foyzulkarim / sampleREADME.md
Created January 7, 2019 19:09 — forked from FrancesCoronel/sampleREADME.md
A sample README for all your GitHub projects.

FVCproductions

INSERT GRAPHIC HERE (include hyperlink in image)

Repository Title Goes Here

Subtitle or Short Description Goes Here

@foyzulkarim
foyzulkarim / HTML page
Created December 2, 2014 15:02
HTML string to PDF. (Problem: Extra zoomed in)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div>
<div class=" container ng-scope" ng-switch=" view">
@foyzulkarim
foyzulkarim / AuthorizationController.cs
Created August 22, 2017 16:12
Role-Based-Access-Control Authorization Logic based on ASP.NET Identity and System.Runtime.Caching.MemoryCache
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net.Http;
using System.Runtime.Caching;
using System.Web.Http;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
@foyzulkarim
foyzulkarim / Program.cs
Created September 8, 2018 03:51
Data Migration using Threading in C#
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using Core = BizBookCoreDbModelLibrary;
using BizBookDbModelLibrary;
@foyzulkarim
foyzulkarim / Get Text From PDF using C# and iTextSharp
Created February 9, 2018 15:25
One of my clients who is currently using BizBook, used Wave for some months, but while they grew bigger, wave stopped supporting to download the invoices as a bulk excel or csv. So, when they decided to jump into BizBook, then they had to export their all existing data into my system. Since the wave didn’t allow csv / excel anymore, so I had no …
private static IEnumerable<string> GetTextFromPDF(string invoicePdf)
{
var fromPdf = new List<string>();
using (PdfReader reader = new PdfReader(invoicePdf))
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
string value = PdfTextExtractor.GetTextFromPage(reader, i);
List<string> list = value.Split(new[] { "\n" }, StringSplitOptions.None).ToList();
list.RemoveAll(Match);
@foyzulkarim
foyzulkarim / BaseReportService.cs
Created February 4, 2018 18:15
Create default instance of the provided type
public class BaseReportService
{
protected T CreateDefault<T>(Type t, string shopId) where T : BaseReport
{
var report = Activator.CreateInstance(t) as BaseReport;
report.Id = Guid.NewGuid().ToString();
report.Created = DateTime.Now;
report.Modified = DateTime.Now;
report.CreatedBy = "System";
report.ModifiedBy = "System";