Skip to content

Instantly share code, notes, and snippets.

View defilerc's full-sized avatar

Konstantinos Athanasoglou defilerc

View GitHub Profile

ORM (What is it?)

  • Convert data between incompatible type systems (Object Oriented structures to relational ones)
  • Idea: Hide dev from DB Construction.
    • Old years: logic in DB. Nowadays: logic in code (testable, with C# you express better your intents)
    • SQL one-to-one (Department - Manager). one-to-many (Department - Employees). many-to-many (Student - Teacher).
      • How to express them in C# ? (e.g. Customer - Order)

EF Core (Introduction)

# Get cmdlets with specific verb
Get-Command -Verb Get
# Get cmdlets with specific verb
Get-Command -Noun Service
# Get cmdlets that end in "-Service"
Get-Command *-Service
# useful commands for rabbitmqctl
# use sudo and drop .bat when run from Linux (no need in Windows):
# get status
rabbitmqctl.bat status
# list exchanges
rabbitmqctl.bat list_exchanges
# list bindings
$smo = 'Microsoft.SqlServer.Management.Smo.'
$wmi = new-object ($smo + 'Wmi.ManagedComputer').
# List the object properties, including the instance names.
$Wmi
# Enable the TCP protocol on the default instance.
$uri = "ManagedComputer[@Name='NT-44']/ ServerInstance[@Name='SQLEXPRESS']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $true
-- see db collation (method 1):
EXECUTE sp_helpsort;
-- see db collation (method 2):
SELECT CONVERT (varchar, SERVERPROPERTY('collation'));
-- Take the Database Offline
ALTER DATABASE [myDB] SET OFFLINE WITH
ROLLBACK IMMEDIATE
GO
# undo last commit (not pushed)
git reset HEAD~
# delete remote branch
git push origin --delete feature/login
# stash changes, including untracked files and give a store message (git save has been deprecated in favor of git push)
git stash push --include-untracked --message "publish scripts & command performance tests"
# commit partial file changes
# write to console
write-host "ok"
# use pipe to write to console
(1, 2, 3, 4, 5, 6) | % { write-host $_ }
# filter elements and write to console
(1, 2, 3, 4, 5, 6) | sort-object -descending | % { write-host $_ }
# get json from http
# c : create archive
# j : use bzip2 (z for gzip)
# v : verbose
# f : use file
# (optional) S : handle sparse files efficiently
tar -cjvf vp-core_stable.tar.bzip2 vp-core_stable\
# x : extract
tar xjvf vp-core_stable.tar.bz2
@defilerc
defilerc / git-patch-apply.sh
Created May 9, 2018 14:19
git: create patch between branches and apply
# checkout branch with changes
# --stdout used to produce 1 diff file, instead of n, where n # of commits.
git format-patch [branch_to_compare_to] --stdout > all.patch
# checkout to new branch. apply patch created
git apply all.patch