Skip to content

Instantly share code, notes, and snippets.

@dmlogv
dmlogv / table-of-integer.sql
Last active June 17, 2019 08:36
Generates the table of integer numbers in Transact-SQL (Microsoft SQL Server)
/*
Result values table
You could change it to permanent table like s/#integers/dbo.Integers/g
*/
DROP TABLE IF EXISTS #integers;
CREATE TABLE #integers (
i INT NOT NULL PRIMARY KEY
);
@dmlogv
dmlogv / random-int.sql
Last active June 17, 2019 10:25
Random integer number in Transact-SQL (Microsoft SQL Server)
/*
Slow method
Pre-use my integer's table: https://gist.github.com/dm-logv/38eb66f5a2a461cb8f42e14714682daa
*/
SELECT TOP 1 i
FROM #integers
ORDER BY NEWID();
@dmlogv
dmlogv / get-date-interval.sql
Created June 17, 2019 10:15
Find days of week interval including a given date
/*
Get date interval
Find days of week interval including @date.
Args:
@date -- Date to find interval
@first -- Interval start (day of week number where 1 is Mon, 7 is Sun)
@last -- Interval start (day of week number where 1 is Mon, 7 is Sun)
@dmlogv
dmlogv / MapCapsToCtrl.reg
Created June 17, 2019 13:13
Map CapsLock to Control (Windows)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
@dmlogv
dmlogv / count-substrings.sql
Created June 17, 2019 13:24
Count substrings
/*
Counts a number of substrings in the given string
Args:
@string
@substring
Returns:
INT
@dmlogv
dmlogv / split-string.sql
Created June 17, 2019 13:36
Split String
/*
Split a string by delimiter and return substrings
Args:
@string NVARCHAR(max),
@delimeter NVARCHAR(100) = ''
Returns:
TABLE
@dmlogv
dmlogv / agent-datetime.sql
Created June 17, 2019 13:42
UDF to convert SQL Server Date/Time to Date/Time
/*
Converts SQL Server Agent Time to Time
*/
CREATE FUNCTION dbo.fnc_agentTimeToTime (
@agent_date INT
)
RETURNS TIME(0)
AS
BEGIN
DECLARE @result TIME(0);
@dmlogv
dmlogv / get-row-count.sql
Last active June 17, 2019 13:58
Get table row count with different methods
/*
Get table row count
See code comments.
See http://blogs.msdn.com/b/martijnh/archive/2010/07/15/sql-server-how-to-quickly-retrieve-accurate-row-count-for-table.aspx
Args:
@table NVARCHAR(1000) , -- Table name (include DB: 'Northwind..tEmployee').
@row_count BIGINT OUTPUT , -- Output result (see example).
@dmlogv
dmlogv / git-manual.md
Last active July 31, 2020 14:11
My Git snippets

Configuration

  • Commons:
    • git config --global http.sslVerify false
  • Don't forget to use proxy!
    • git config --global http.proxy dm-logv:pass123@mwg:3128
    • git config --global https.proxy dm-logv:pass123@mwg:3128
  • Don't forget to set name and email:
    • git config user.name "Dmitry Logvinenko"
  • git config user.email "5diezfun@gmail.com"
@dmlogv
dmlogv / Dockerfile
Created June 19, 2019 07:59
Dockerfile with the one-line nc-based webserver
FROM busybox:latest
ENV port=8081
RUN \
echo -e 'echo $port\n\nwhile true\ndo\n (echo -e "HTTP/1.1 200 OK\\nContent-Type: text/html\\n\\n<b>Hello World</b><br>Builded at $(date)";) | nc -vv -l -p $port\ndone' > server.sh \
&& chmod +x server.sh \
&& mkdir /var/log
EXPOSE 8081:8081