Skip to content

Instantly share code, notes, and snippets.

View juanonsoftware's full-sized avatar

Juan on Software juanonsoftware

  • Rabbit Software
  • Vietnam
View GitHub Profile
@juanonsoftware
juanonsoftware / gist:7067ce53813201abbdae
Last active August 29, 2015 14:23
C# Convert null property to Empty JSON object by property's type
namespace JsonConvertNullToEmpty
{
public class Main
{
public Child First
{
get;
set;
}
@juanonsoftware
juanonsoftware / gist:b55bcf15923f3f9cd2f4
Created June 29, 2015 09:40
C# LINQ with join on multiple properties
namespace ConsoleApplication1
{
public class Context
{
public IList<Product> Products { get; set; }
public IList<Company> Companies { get; set; }
}
public class Product
{
@juanonsoftware
juanonsoftware / gist:f4b3e85415ccdcab2161
Created July 3, 2015 16:04
NHiberate - Code to make SchemaExport generate database for entities mapping class
using System;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Tool.hbm2ddl;
namespace ConsoleApplication1
{
@juanonsoftware
juanonsoftware / sql-backup-database-diff
Last active April 12, 2018 09:52
Script to backup an SQL Server database
-- NOTE
-- Must update dbName & Folder
declare @dbName nvarchar(150);
declare @folder nvarchar(100);
set @dbName = 'TestDB';
set @folder = 'D:\Mega\Wip\SQL\TestDB\Backup\';
declare @path nvarchar(255);
@juanonsoftware
juanonsoftware / sql-get-db-backups.sql
Last active April 12, 2018 10:00
Script to get all backup of a SQL Server database
declare @dbName varchar(255);
set @dbName = 'TestDB';
SELECT m.physical_device_name,
b.backup_start_date,
b.backup_finish_date,
b.type,
b.backup_size/1024/1024 AS BackupSizeMB,
b.compressed_backup_size/1024/1024 as CompressedBackupSizeMB
@juanonsoftware
juanonsoftware / sql-get-running-jobs.sql
Last active April 12, 2018 10:00
To get all jobs that are running on an instance
SELECT
ja.job_id,
j.name AS job_name,
ja.start_execution_date,
ISNULL(last_executed_step_id,0)+1 AS current_executed_step_id,
Js.step_name
FROM msdb.dbo.sysjobactivity ja
LEFT JOIN msdb.dbo.sysjobhistory jh
ON ja.job_history_id = jh.instance_id
JOIN msdb.dbo.sysjobs j
@juanonsoftware
juanonsoftware / remove-all-messages-in-sql-queue.sql
Created April 26, 2018 08:45
To empty all messages from a queue
begin tran
declare @c uniqueidentifier
while(1=1)
begin
select top 1 @c = conversation_handle from dto.YourQueueName
if (@@ROWCOUNT = 0)
break
end conversation @c with cleanup
end
@juanonsoftware
juanonsoftware / Search StoredProcedures by name.sql
Created May 2, 2018 08:02
Search for stored procedures in a given database
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
ORDER BY modify_date desc, create_date desc
@juanonsoftware
juanonsoftware / ChocoInstallCommonSoftwareForServer.ps1
Last active May 15, 2018 07:45
Common and Must have software for a Windows server installation script via Chocolatey. Just need to run this script in a Powershell console (with Administrator right)
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# 7Zip - https://chocolatey.org/packages/7zip
choco install 7zip -y
# Notepad++ - https://chocolatey.org/packages/notepadplusplus.install
choco install notepadplusplus.install -y
# TreeSize Free https://chocolatey.org/packages/treesizefree
choco install treesizefree -y
@juanonsoftware
juanonsoftware / ChocoInstallSqlServer2014WithManagementStudio.ps1
Created May 15, 2018 07:55
Powershell script to install SQL Server 2014 and SQL Server Studio Management via Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install SQL Server 2014 Management Studio
choco install mssqlservermanagementstudio2014express -y --version 12.2.5000.20170905
# Install SQL Server 2014
choco install mssqlserver2014express -y --version 12.2.5000.20170905