15 Eylül 2020 Salı

JavaScript dizi kopyalama , referanssız

 1. JSON.parse(JSON.stringify(input))

 

2.

let oldArray = [1, 2, 3, 4, 5];

let newArray = oldArray.slice(); 
 
 
 

 

8 Eylül 2020 Salı

Ubuntu klasör izni

 klasöre kullanıcı yetkisi yok ve root kullanıcısı istiyorsa o klasöre 777 yetkisi verirsek tüm kullanıcılara yetki vermiş oluyoruz. dikkatli kullanmak lazım     

chmod -R 777 /www/store

31 Ağustos 2020 Pazartesi

Enlem boylam uzaklık hesaplama (c#)

 using System;

namespace Falcon.Core.Helpers
{
    public class GeoCalculator
    {
        private static double ToRadians(double degree)
        {
            return (degree * Math.PI) / 180;
        }

        public static double Distance(double latitude1, double latitude2, double longitude1, double longitude2)
        {
            // The math module contains
            // a function named toRadians
            // which converts from degrees
            // to radians.
            longitude1 = ToRadians(longitude1);
            longitude2 = ToRadians(longitude2);
            latitude1 = ToRadians(latitude1);
            latitude2 = ToRadians(latitude2);

            // Haversine formula
            double diffLongitude = longitude2 - longitude1;
            double diffLatitude = latitude2 - latitude1;
            double a = Math.Pow(Math.Sin(diffLatitude / 2), 2) +
                       Math.Cos(latitude1) * Math.Cos(latitude2) *
                       Math.Pow(Math.Sin(diffLongitude / 2), 2);

            double c = 2 * Math.Asin(Math.Sqrt(a));

            // Radius of earth in
            // kilometers. Use 3956
            // for miles
            double r = 6371;

            // calculate the result
            return (c * r);
        }
    }
}

Enlem boylam uzaklık hesaplama

 

Since you're using SQL Server 2008, you have the geography data type available, which is designed for exactly this kind of data:

DECLARE @source geography = 'POINT(0 51.5)'
DECLARE @target geography = 'POINT(-3 56)'

SELECT @source.STDistance(@target)

Gives

----------------------
538404.100197555

(1 row(s) affected)

Telling us it is about 538 km from (near) London to (near) Edinburgh.

Naturally there will be an amount of learning to do first, but once you know it it's far far easier than implementing your own Haversine calculation; plus you get a LOT of functionality.


If you want to retain your existing data structure, you can still use STDistance, by constructing suitable geography instances using the Point method:

DECLARE @orig_lat DECIMAL(12, 9)
DECLARE @orig_lng DECIMAL(12, 9)
SET @orig_lat=53.381538 set @orig_lng=-1.463526

DECLARE @orig geography = geography::Point(@orig_lat, @orig_lng, 4326);

SELECT *,
    @orig.STDistance(geography::Point(dest.Latitude, dest.Longitude, 4326)) 
       AS distance
--INTO #includeDistances
FROM #orig dest

14 Mayıs 2020 Perşembe

Veritabanı ortamları oluşturma

DECLARE @environments TABLE (Environment VARCHAR(255) not null);
INSERT @environments(Environment) VALUES ('Test'),('Dev'),('DevAkif'),('DevGuest');
DECLARE @environment VARCHAR(255);
DECLARE @prefix VARCHAR(255)='DB_Name_';
DECLARE @path VARCHAR(255) =N'C:\MSSQL\Backup\Yesterday\Backup.bak';
DECLARE @backup_dbname VARCHAR(255) = 'DB_Name';
DECLARE @backup_dbname_log VARCHAR(255) = 'DB_Name_log';
DECLARE @data_path VARCHAR(255) ='C:\MSSQL\DATA\';
DECLARE @mdf VARCHAR(4)= '.mdf';
DECLARE @log VARCHAR(4)='_log';
DECLARE @ldf VARCHAR(4)= '.ldf';

DECLARE CreateEnvironmentsCursor CURSOR FOR
SELECT Environment FROM @environments;

OPEN CreateEnvironmentsCursor 
FETCH NEXT FROM CreateEnvironmentsCursor INTO @environment ;

WHILE @@FETCH_STATUS = 0 
BEGIN 
    PRINT @environment+ ' yedek alınıyor...';
    DECLARE @environment_db_name VARCHAR(255) =@prefix+@environment;
    DECLARE @environment_logical_name VARCHAR(255) = @environment_db_name;
    DECLARE @environment_mdf_path VARCHAR(255) = @data_path +@environment_db_name+ @mdf;
    DECLARE @environment_logical_log_name VARCHAR(255) = @environment_db_name + @log;
    DECLARE @environment_ldf_path VARCHAR(255) = @data_path +@environment_db_name+@log+@ldf;
    IF EXISTS (SELECT name FROM sys.databases WHERE name = @environment_db_name)
        BEGIN
            EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = @environment_db_name
            USE [master]
            EXEC('DROP DATABASE '+@environment_db_name)
        END
    RESTORE FILELISTONLY FROM DISK=@path

    RESTORE DATABASE @environment_db_name
    FROM DISK = @path
    WITH
    MOVE @backup_dbname TO @environment_mdf_path,
    MOVE @backup_dbname_log TO @environment_ldf_path

    EXEC('ALTER DATABASE '+@environment_db_name+' MODIFY FILE (NAME=['+@backup_dbname+'], NEWNAME='+@environment_logical_name+')');
    EXEC('ALTER DATABASE '+@environment_db_name+' MODIFY FILE (NAME=['+@backup_dbname_log+'], NEWNAME='+@environment_logical_log_name+')');

    EXEC('USE '+@environment_db_name +'; '
     +' ALTER DATABASE '+@environment_logical_name+' SET RECOVERY SIMPLE WITH NO_WAIT;'
    +'DBCC SHRINKFILE('+@environment_logical_log_name+') ;'
    +'ALTER DATABASE '+@environment_logical_name+' SET RECOVERY FULL WITH NO_WAIT;');

    IF USER_ID(@environment_db_name) IS NULL
    BEGIN
        CREATE USER [TestUser] FOR LOGIN [TestUser] -- Önceden oluşturulan user
    END
        ALTER ROLE [db_owner] ADD MEMBER [TestUser]

    FETCH NEXT FROM CreateEnvironmentsCursor INTO @environment
END

CLOSE CreateEnvironmentsCursor 
DEALLOCATE CreateEnvironmentsCursor

13 Mayıs 2020 Çarşamba

SINGLE USER modundan veritabanını MULTI USER olarak ayarlama

use master
GO

select 
    d.name, 
    d.dbid, 
    spid, 
    login_time, 
    nt_domain, 
    nt_username, 
    loginame
from sysprocesses p 
    inner join sysdatabases d 
        on p.dbid = d.dbid
where d.name = 'dbname'
GO

kill 56 --=> kill the number in spid field
GO

exec sp_dboption 'dbname', 'single user', 'FALSE'
GO
 
 
 
 
https://stackoverflow.com/questions/14652923/set-database-from-single-user-mode-to-multi-user 

Is there any way to get a list of open/allocated cursors in SQL server?

USE MASTER
GO
select s.session_id, s.host_name, s.program_name, s.client_interface_name, s.login_name
, c.cursor_id, c.properties, c.creation_time, c.is_open, con.text,
l.resource_type, d.name, l.request_type, l.request_Status, l.request_reference_count, l.request_lifetime, l.request_owner_type
from sys.dm_exec_cursors(0) c
left outer join (select * from sys.dm_exec_connections c cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) mr) con on c.session_id = con.session_id
left outer join sys.dm_exec_sessions s on s.session_id = c.session_id
left outer join sys.dm_tran_locks l on l.request_session_id = c.session_id
left outer join sys.databases d on d.database_id = l.resource_database_id


Açık kalan Cursorları listeleme


Kaynak: https://stackoverflow.com/questions/265605/is-there-any-way-to-get-a-list-of-open-allocated-cursors-in-sql-server

.net 6 mapget kullanımı

 app.UseEndpoints(endpoints => {     endpoints.MapGet("/", async context =>     {         var response = JsonConvert.Seriali...