2021-02-19

SQLs you need to improve performance of you Azure SQL databases

 Check index fragmentation:


SELECT
 DB_NAME() AS DBName
 ,OBJECT_NAME(ps.object_id) AS TableName
 ,i.name AS IndexName
 ,ips.index_type_desc
 ,ips.avg_fragmentation_in_percent
 FROM sys.dm_db_partition_stats ps
 INNER JOIN sys.indexes i
 ON ps.object_id = i.object_id
 AND ps.index_id = i.index_id
 CROSS APPLY sys.dm_db_index_physical_stats(DB_ID(), ps.object_id, ps.index_id, null, 'LIMITED') ips
 ORDER BY ps.object_id, ps.index_id


List slowest sql executions with QueryPlans (if you save them as .sqlplan you can easily open it in Management Studio)

SELECT  qs.max_worker_time, qs.max_elapsed_time, st.text,
        qp.query_plan,
        qs.*
FROM    (
    SELECT  TOP 50 *
    FROM    sys.dm_exec_query_stats
    ORDER BY total_worker_time DESC
) AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
WHERE qs.max_worker_time > 300
      OR qs.max_elapsed_time > 300
ORDER BY qs.max_elapsed_time DESC



Next query:

SELECT ...


2020-08-07

Hosting SPA apps with html5 history on Azure Linux app service

Quick answear


1. Set Configuration -> General settings Stack to PHP
2. create a .htaccess file in /home/site/wwwroot

With content:

RewriteEngine On

RewriteRule "^[^\.]+$" "index.html"


Done

2016-11-02

TFS: Automate deploy Xamarin Android project to Google Play Store

TFS (also VSTS) is able to build, test and deploy your .net projects. Below you will find simple tutorial how to build and deploy Xamarin Android app on Visual Studio Team Services and automate deploy to Google Play Store. 

Actions on Google play / Google developer console

Important: Before automating deploy application needs to be deployed manually for the first time:

Go to google play dev console, create new project, upload apk into alpha tests

Fill all necessary fields (icons, images, set catrgories) and deploy:



Enable api access to google play developer console:
Connect Google Developer poject with play console:
Create account:

Set proviliges:

(Administrator is probably too much, but i didnt have time for checkin other )

Download Google Play Android developer json, it will look like this:


Add necessary files to solution and deploy

Generate keystore file

and add it to solution (the file isused to sign your apk file so do not share it with others )

TFS

Install Google play from Visual Studio Marketplace


Go to settings ->; Services
Add new service endpoint: Google Play


Service Account email: take email address from Google Play Console
Private kay: Take it from downloaded json from google developer console.
You can download the file from here:


Open json file and take copy private kay to TFS: 




Go to Build & Release, add new build definition: Xamarin.Android:


Enable Apk sign and align


Add new build step: Google Play Release


And configure it:

Done. Save and Start build.


2016-09-14

Kali Linux on USB with Persistence and Windows partition

The goal 

Both Kali Linux with persistence and standard data storage accessible from Windows on one usb drive.

The Tools:

Usb drive - I used 32Gb USB 3.0 mini pendrive
Kali Linux iso
MiniTool Partition Wizard Free - used to repartition usb drive
Win32 Disk Imager - used to install Kali iso image
Bootice - used set partition to be wisible in windows

Action:

1. Use MiniTool Partition Wizard to remove all data from pendrive, remove all partitions and create one, full drive size, format fat32
2. Use Win32 disk imager to install Kali on drive
3. Use Partition Wizard to create 2 partitions:
3a: Kali persistence partition: create Ext2 partition and name it persistence (this is important)
3b: Windows data partition: create Fat32 (or ntfs)
4. Use bootice to make Windows partition accessible:
4.1. In Destination Disk select usb drive
4.2. Click Parts Manage
4.3. In Partition Management window select windows partition
4.4. Click Assign drive letter
4.5. Close Bootice

6. Open Partition Wizard to check if everything is ok:
Your drive should look like this:


2.76 GB is Kali partition
105.00 MB is some reserved partition
8.89 GB is Kali persistence partition
17.11 GB is windows partition (i named it MINIUSB)

6. Boot to Kali and finish configuring peristence:
open termianl and type:

lsblk

Find your persistence partition device it will be /dev/sdbX where X in number 
Use it to replace sdbX from script below and run it :

mkdir -p /mnt/my_usb
mount /dev/sdbX /mnt/my_usb
echo "/ union" > /mnt/my_usb/persistence.conf
umount /dev/sdbX

6. Restart Kali, in boot menu select "with persistance"




Credits:
http://null-byte.wonderhowto.com/how-to/kali-is-your-new-pet-ultimate-guide-about-kali-linux-portability-0157538/

https://forums.kali.org/showthread.php?24476-A-Windows-Only-Method-For-Creating-A-Live-Kali-USB-With-Persistence

2016-07-14

TFS Build Triggers

The Problem

My solution contains both WebApi and UI (AngularJS app) project.
I would like to have two build definitions:

  • Api build -  Build web.api project, run unit tests, deploy on Azure
  • UI build - Run NPM, Grunt, and deploy on different Azure website 
I would like to build/deploy projects only when I push changes to particular project, so when I push changes to UI only UI build schould be triggered.


Preparation

I already manage to build and deploy both projects separatly. The only thing I need to do is configure build triggers.

Project structure

My project structure in silution is:

Where:
Furcas.Api is Web.Api priject
Furcas.Cli is Web project (AngularJs app)
Furcas.Engine is bussiness logic for web.api

If your VSTS project supports GIT as version control system


WebApi build definition
Note that build will be triggered if changes were made in Furcas.Api or Furcas.Engine project
Things to remember: Path should start with /



UI build definition:

If your VSTS project supports Team Foundation as version control system

(You pinked: 

)

VSTS provides picker for TFS paths










2013-08-22

Calculating Interest rate in SQL Server - PPMT / IPMT / PMT

A few days ago I was asked to create simple tool for calculating Interest rate. I received also excel file with all necessary calculations and formulas. Most of formulas used excel financial functions: PPMT , IPMT . I started with googling for SQL port of PPMT but I didnt find anything except this:
SQL Server – Excel Financial Functions – using CLR
Its quite ok, but I noticed that CLR functions are rounded to two decimal plaseces witch was not acceptable for me so I wrote my own functions based on this article: A Guide to the PMT, FV, IPMT and PPMT Functions
Below you will find T-SQL version of  PPMT / IPMT / PMT / FV excel financial functions

 
IF OBJECT_ID('Pmt', 'FN') IS NOT NULL DROP FUNCTION dbo.Pmt  
GO  
CREATE FUNCTION dbo.Pmt (@r NUMERIC(18,4), @nper INT, @pv NUMERIC(18,4), @fv NUMERIC(18,4), @type INT)  
RETURNS NUMERIC(18,4)
AS  
BEGIN  
 DECLARE @pmt NUMERIC(18,4)  
 
 SET @pmt = @r / (Power(1.0 + @r, @nper) - 1.0) * -(@pv * Power(1.0 + @r, @nper) + @fv)  
 
 if @type = 1  
 SET @pmt = @pmt / (1 + @r)  
 RETURN @pmt  
END  
GO  


IF OBJECT_ID('Fv', 'FN') IS NOT NULL DROP FUNCTION dbo.Fv  
GO  
CREATE FUNCTION dbo.Fv (@r NUMERIC(18,4), @nper INT, @c NUMERIC(18,4), @pv NUMERIC(18,4), @type INT)  
RETURNS NUMERIC(18,4)
AS  
BEGIN  
 DECLARE @fv NUMERIC(18,4)  
 
 IF @type = 1  
 SET @c = @c * (1 + @r);  
 
 SET @fv = -(@c * (Power(1 + @r, @nper) - 1) / @r + @pv  
    * Power(1 + @r, @nper))  
 
 RETURN @fv  
END  
GO  

IF OBJECT_ID('Ipmt', 'FN') IS NOT NULL DROP FUNCTION dbo.Ipmt  
GO  
CREATE FUNCTION dbo.Ipmt (@r NUMERIC(18,4), @per INT, @nper INT, @pv NUMERIC(18,4), @fv NUMERIC(18,4), @type INT)  
RETURNS NUMERIC(18,4)   
AS  
BEGIN  
 DECLARE @ipmt NUMERIC(18,4)  
 SET @ipmt = dbo.Fv(@r, @per - 1, dbo.Pmt(@r, @nper, @pv, @fv, @type), @pv, @type) * @r  
 
 if @type = 1  
 SET @ipmt = @ipmt / (1 + @r)  
 RETURN @ipmt  
END  
GO  

IF OBJECT_ID('Ppmt', 'FN') IS NOT NULL DROP FUNCTION dbo.Ppmt  
GO  
CREATE FUNCTION dbo.Ppmt (@r NUMERIC(18,4), @per INT, @nper INT, @pv NUMERIC(18,4), @fv NUMERIC(18,4), @type INT)  
RETURNS NUMERIC(18,4)   
AS  
BEGIN  

 RETURN dbo.Pmt(@r, @nper, @pv, @fv, @type) - dbo.Ipmt(@r, @per, @nper, @pv, @fv, @type);  

END  
GO

2013-02-25

Allegro.pl WebApi for .Net

I just published my open source project: AllegroWebApi for .Net. - it really simplifies usage of Allegro.pl web api.
Project is available at https://code.google.com/p/allegro-web-api/
Here is sample code:

 // Dont forget about usings!  
 uses AllegroWebAPI;  
 // This is main class  
 var api = new AllegroClient("YOUR API KEY HERE");  
 // Some functions needs your login/password to work properly  
 api.Login("YOUR ALLEGRO LOGIN", "YOUR ALLEGRO PASSWORD");  
 // Get my data   
 MyAllegro my = new MyAllegro(api);        
 Console.WriteLine(my.MyData.Email);  
 // Get user Id by user login  
 long uid = api.GetUser("ja-biel").Id;  
 // Retrieve user feedback  
 Feedback feedback = new Feedback(api);  
 foreach (var qq in feedback.GetFeedback(uid, CommentTypeAll.All))  
 {  
   Console.WriteLine(qq.fDesc);  
 }  

Hope someone like it.

2011-01-02

EDIMAX 6200n - linux command line


Since 2 months I have new cool toy - Edimax 6200n
Edimax 6200n wasn't expensive, it cost about 40$
it supports most of 3G modems, firmware is often updated, based on linux 2.6.21 (linux sources available on edimax site) but ..
No linux shell :(

After I downloaded sources and make little research i found this:
http://192.168.2.1/syscmd.asp

Thank you Edimax developers

2009-02-27

Sybase to MSSQL: Getting stored procedure parameters

I started job in new company! This is good news.
Now i will work on Sybase - this is not so good but ok..
Version of db i will use is:
Adaptive Server Enterprise/12.5.0.2/EBF
And this is definitely not good.. its from 2001 :) .. a bit old. 

I'm MS SQL Server fan. As a database developer I really appreciate work done by MS guys in developing SQL server tools: Profiler, Managment studio..
Also some usefull objects are commonly used in my daily work.
Lack of INFORMATION_SCHEMA views was one of first thing I noticed.
And this is my today task: INFORMATION_SCHEMA.PARAMETERS

 CREATE VIEW dbo.INFORMATION_SCHEMA_PARAMETERS  
 AS  
 SELECT db_name() SPECIFIC_CATALOG,  
 user_name(sp.uid) SPECIFIC_SHEMA,  
 sp.name SPECIFIC_NAME,  
 colid ORDINAL_POSITION,  
 param.name PARAMETER_NAME,  
 CASE param.status2 WHEN 2 THEN 'OUT' ELSE 'IN' END PARAMETER_MODE,  
 t.name AS DATA_TYPE,  
 t.length LENGTH  
 FROM dbo.sysobjects AS sp  
 INNER JOIN syscolumns AS param ON (param.number = 1) AND (param.id=sp.id)  
 LEFT JOIN systypes AS t ON t.usertype = param.usertype  
 GO 
 
 CREATE VIEW INFORMATION_SCHEMA_TABLES  
 AS  
 SELECT  
 db_name() AS TABLE_CATALOG,  
 user_name(uid) AS TABLE_SCHEMA,  
 o.name AS TABLE_NAME,  
 CASE o.type  
 WHEN 'U' THEN 'BASE TABLE'  
 WHEN 'V' THEN 'VIEW'  
 END AS TABLE_TYPE  
 FROM sysobjects o  
 WHERE o.type IN ('U', 'V')  
 GO 
 
 CREATE VIEW INFORMATION_SCHEMA_COLUMNS  
 AS  
 SELECT db_name() TABLE_CATALOG,  
 user_name(o.uid) TABLE_SHEMA,  
 o.name TABLE_NAME,  
 c.name COLUMN_NAME,  
 colid ORDINAL_POSITION,  
 t.name AS DATA_TYPE,  
 t.length LENGTH,  
 CASE WHEN allownulls = 1 THEN 'YES' ELSE 'NO' END IS_NULLABLE  
 FROM dbo.sysobjects AS o  
 INNER JOIN syscolumns AS c ON (c.number = 0) AND (c.id=o.id)  
 LEFT JOIN systypes AS t ON t.usertype = c.usertype  
 GO  

As you can see my version of INFORMATION_SCHEMA_PARAMETERS is pretty simpler than the MS version, but most impotent things are in ..