Skip to content

Instantly share code, notes, and snippets.

@farukcan
farukcan / git.json
Last active February 28, 2023 19:51
Git Commands - Visual Powershell Repository
{
"Name" : "Git Commands",
"Author": "farukcan",
"Website" : "https:/farukcan.net",
"Commands" : [
{
"Name" : "🚀 Initialize folder",
"Scripts" : ["git init"]
},
{
@farukcan
farukcan / info.md
Last active February 23, 2023 22:19
Postgres Dotnet Core
  • Auto create Context by Visual Studio. (Connected Services -> Add -> PostgreSQL)
  • Install NuGet package : Microsoft.EntityFrameworkCore
  • Install NuGet package : Npgsql.EntityFrameworkCore.PostgreSQL
  • Add code :
builder.Services.AddDbContext<LocationAppContext>(options =>
    options.UseNpgsql(System.Environment.GetEnvironmentVariable("POSTGRESQL_STRING") ?? throw new InvalidOperationException("Connection string 'LocationAppContext' not found."),
    options => options.EnableRetryOnFailure().SetPostgresVersion(new Version(9, 6))
    ));
@farukcan
farukcan / gist:3631cc0024953b1d4c1e6a5448f36562
Created February 19, 2023 17:46
C# Action, Func and Task
Action : Gets parameters. (x) => {} . Action , Action<int>
Func : Gets parameters and returns value. (x) => y or (a,b) => { return y; } . Func<int,int> . (last generic is return value type)
Task : Gets parameters, works async, may return value. async (x) => {...await y()...} , or async (x) => await y(x). async Task<int>.
@farukcan
farukcan / Notion.cs
Created November 3, 2022 14:41
Fast DotNetCore Notion Integration
using Notion.Client;
namespace NotionQuickBlog.Data
{
public static class Notion
{
public static string? Token => Environment.GetEnvironmentVariable("NOTION_TOKEN");
static NotionInstance? instance;
public static NotionInstance Instance => instance!=null ? instance : (instance=new NotionInstance());
public static NotionClient Client => Instance.client;
@farukcan
farukcan / Sha256Helper.cs
Created November 3, 2022 14:38
C# SHA256 Helper
using System.Security.Cryptography;
using System.Text;
namespace FarukCan.Helpers
{
public static class Sha256Helper
{
public static string GetSha256Hash(this string input,string salt="")
{
using (SHA256 sha256Hash = SHA256.Create())
@farukcan
farukcan / SessionExtension.cs
Last active November 3, 2022 14:36
DotNetCore Session Extension
using System.Text.Json;
using Microsoft.AspNetCore.Http;
// source : https://www.learmoreseekmore.com/2020/05/dotnet-core-session.html
// usage : InfoModel info = HttpContext.Session.Get<InfoModel>("info");
// usage : HttpContext.Session.Set<InfoModel>("info", info);
namespace SessionMvc.App.Utilities
{
public static class SessionExtension
{
public static void Set<T>(this ISession session, string key, T value)
@farukcan
farukcan / vscode-omnisharp.md
Created October 26, 2022 17:58 — forked from stormwild/vscode-omnisharp.md
Visual Studio Code Restart OmniSharp
@farukcan
farukcan / net.md
Created October 21, 2022 14:48
.NET Core/Framework diff

.NET Core is a free open source, a general-purpose development platform for developing modern cloud-based software applications on Windows, Linux, and macOS operating systems. It operates across several platforms and has been revamped to make .NET fast, scalable, and modern. .NET Core is one of Microsoft’s big contributions and released under the MIT License. It offers the following features:

Cross-Platform Open Source High Performance Multiple environments and development mode etc.

What to use .NET Framework or .NET Core?

.NET Core is to be used for the server application when –

@farukcan
farukcan / note.md
Created October 20, 2022 23:36
Use npm and asp dotnet together

use node_modules folder as static folder /lib

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "node_modules")),
    RequestPath = "/lib",
        
    OnPrepareResponse = ctx =>
 {
@farukcan
farukcan / .gitignore
Created October 20, 2022 23:32
gitignore file for asp dotnet core 6
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache