Skip to content

Instantly share code, notes, and snippets.

@shturm
shturm / dotnet.md
Last active September 6, 2023 07:41
DotNetCore 6/7 ASP.NET CLI cheatsheet

Create new asp.net site with SQLite database dotnet new mvc -au Individual

Cross compile on Windows for Ubuntu: dotnet publish --runtime ubuntu.22.04-x64 -c Release then to run it dotnet myprojname.dll

Create a minimal dotnet 7 app with anonymous function for endpoints dotnet new web

@shturm
shturm / sublime.reg
Created October 22, 2022 05:13
Add "Open folder in Sublime Text 3" to windows explorer context menu
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\sublime_text]
@="Open with Sublime Text"
"Icon"="\"C:\\Program Files\\Sublime Text\\sublime_text.exe\",0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\sublime_text\command]
@="C:\\Program Files\\Sublime Text\\sublime_text.exe \"%1\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\sublime_text]
@shturm
shturm / wgetpager.sh
Created January 25, 2019 16:55
wget a page recursively or not
#!/bin/bash
echo "Getting $2 levels of $1"
if [ "$2" = "" ]; then
wget -k -p -nc -r -l 1 $1
exit
fi
wget -k -p -nc -r -l $2 $1
@shturm
shturm / razor.render.cs
Created January 18, 2018 09:21
Render Razor For Email/Page
protected string GetRenderedPartial(string viewName, object model = null)
{
using (var sw = new StringWriter())
{
if (ControllerContext != null)
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View, new ViewDataDictionary(model), TempData, sw);
viewResult.View.Render(viewContext, sw);
}
@shturm
shturm / Pager.cs
Created November 29, 2017 11:10
AspNetCore pagination
public class Pager
{
public Pager(int totalItems, int? page, int pageSize = 10)
{
// calculate total, start and end pages
var totalPages = (int)Math.Ceiling((decimal)totalItems / (decimal)pageSize);
var currentPage = page != null ? (int)page : 1;
var startPage = currentPage - 5;
var endPage = currentPage + 4;
if (startPage <= 0)
@shturm
shturm / upload.cs
Created November 3, 2017 13:36
c# post json
protected async Task UploadPost(Post post, string endpoint)
{
var client = new HttpClient();
var json = JsonConvert.SerializeObject(post, Formatting.Indented);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var url = $"{endpoint}";
var response = await client.PostAsync(url, content);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Could not upload post {post.DetailsUri}: {response.ReasonPhrase}");
@shturm
shturm / dnxexamples.md
Last active April 7, 2017 15:55
.NET Core Примери

.NET Core примери

Създаване на нов уеб проект

$ mkdir MyProject
$ cd MyProject
$ dotnet new mvc --auth Individual

Обновяване на базата

@shturm
shturm / linux-restore-commands.sh
Created March 30, 2017 15:16
linux-restore-commands.sh
# Restore a complete copy of the SSD (sda device)
gunzip -c /media/data/IMAGE_NAME.img.tgz | dd of=/dev/sda
# Create and compress complete backup of sda (the SSD) disk
dd if=/dev/sda conv=sync,noerror bs=1k | gzip -c > "ssd_sda_`date '+%Y%m%d'`.img.gz"
# Remove LVM the snapshot
sudo lvremove /dev/ubuntuvg/rootsnap
# Create LVM snapshot

Generate a self-signed certificate:

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

Combine separate crt and key files in pfx:

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt

LVM Cheatsheet

Table of commands

Logical Volume Management (LVM) | Physical Volume (PV) | Volume Group (VG) | Logical Volume (LV) --- | --- | --- | --- | --- s | NO | YES | YES | YES display | NO | YES | YES | YES create | NO | YES | YES | YES rename | NO | NO | YES | YES