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 / sql-check-index-fragmentation.sql
Last active January 26, 2022 17:32
Check Fragmentation of ALL Indexes in a Database
-- https://myadventuresincoding.wordpress.com/2013/05/27/sql-server-check-index-fragmentation-on-all-indexes-in-a-database/
SELECT dbschemas.[name] as 'Schema',
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]
@juanonsoftware
juanonsoftware / gist:103fec4fa9c5b9e2ab14
Last active January 26, 2022 17:02
Displaying image from webapi using javascript base64
WebAPI
// GET api/values
public dynamic Get()
{
var root = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var path = Path.Combine(root, "App_Data/Koala.jpg");
var bytes = File.ReadAllBytes(path);
var base64 = Convert.ToBase64String(bytes);
@juanonsoftware
juanonsoftware / RavenDB - Start with RavenDB 4.2.txt
Last active May 20, 2021 03:07
Steps to start working with RavenDB version 4.2
This contains some steps to start working with RVDB 4.2
1. Download the zip at https://ravendb.net/download
2. Unzip to a folder eg D:\Tools\RavenDB\RavenDB-4.2.113-windows-x64
3. Start a PowerShell in Admin mode and change to RVDB folder, execute run.ps1 script
4. Go through some simple steps, ignore configuring any server certificate, we can start using RVDB at this address: http://127.0.0.1:8080/studio/index.html
@juanonsoftware
juanonsoftware / remove-useless-characters.cs
Created October 1, 2020 11:00
Remove useless characters from a text stream (read from a text file / html file....)
// Remove multi spaces
const string reduceSpaces = @"[ ]{2,}";
var finalText = Regex.Replace(allText.Replace('\t', ' '), reduceSpaces, " ");
// Remove empty lines
const string emptyLine = @"^\s+$[\r\n]*";
var finalText = Regex.Replace(finalText, emptyLine, string.Empty, RegexOptions.Multiline);
@juanonsoftware
juanonsoftware / pdf-text-extraction.cs
Last active October 1, 2020 10:37
C# How to get text from PDF file with iTextSharp
// source is a byte array
using (var reader = new PdfReader(source))
{
using (var output = new StringWriter())
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
output.WriteLine(PdfTextExtractor.GetTextFromPage(reader, i));
}
@juanonsoftware
juanonsoftware / docker-ps-commands.ps1
Last active September 19, 2020 08:42
This file contains some common PowerShell commands to work with Docker
# Remove ALL containers
docker ps -a -q | % { docker rm $_ }
# Stop and then remove all RUNNING containers
docker ps -q | % { docker stop $_; docker rm $_ }
# Dockerfile command to create a L drive from C:\Logs folder
RUN Set-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices' -Name 'L:' -Value '\??\C:\Logs' -Type String;
@juanonsoftware
juanonsoftware / Config ARR as a Proxy Server.md
Created November 1, 2018 15:25
Config ARR as a Proxy Server

Steps to config ARR as a Proxy Server for AutoACME

1/ Go to ARR Cache, then Server Proxy Settings

2/ Check on Enable proxy

3/ Create a site call AutoACME and add a binding to support autoacme.com port 80

4/ Go to URL Rewrite

@juanonsoftware
juanonsoftware / Config ARR as a Proxy Server.md
Created November 1, 2018 15:24
Config ARR as a Proxy Server

Steps to config ARR as a Proxy Server for AutoACME

1/ Go to ARR Cache, then Server Proxy Settings

2/ Check on Enable proxy

3/ Create a site call AutoACME and add a binding to support autoacme.com port 80

4/ Go to URL Rewrite

@juanonsoftware
juanonsoftware / Restore database.sql
Created October 22, 2018 08:30
Restore a SQL Server database from backup files
-- Get all db files from a bak
RESTORE FILELISTONLY
FROM DISK = 'Path to full backup file'
GO
-- Restore database from a bak with move logical files (note on NORECOVERY)
RESTORE DATABASE FindTheBest FROM DISK = 'Path to full backup file'
WITH MOVE 'Data file 1' TO 'Path to data file',
MOVE 'Log file 1' TO 'Path to log file',
NORECOVERY
@juanonsoftware
juanonsoftware / README.md
Created September 6, 2018 09:43 — forked from magnetikonline/README.md
PowerShell execute command (.exe) with arguments safely (e.g. with spaces).

PowerShell execute command with arguments safely

In my opinion this is the best way for executing external commands from PowerShell with arguments in a safe manner - via the use of an array to hold the arguments.

Consider this one a PowerShell gem to keep in the toolbox.

Note: the example below makes use of EchoArgs.exe - a small utility that simply echoes back arguments passed to it. Utility is part of the PowerShell Community Extensions, or the exe alone can be downloaded at http://ss64.com/ps/EchoArgs.exe.

Example

Running example.ps1 yields the following output: