Skip to content

Instantly share code, notes, and snippets.

View tdittmar's full-sized avatar

Thorsten Dittmar tdittmar

View GitHub Profile
@tdittmar
tdittmar / db.rpz
Last active September 20, 2024 14:45
Creating an RPZ with BIND9
$TTL 60
@ IN SOA localhost. root.localhost. (
2015112501 ; serial
1h ; refresh
30m ; retry
1w ; expiry
30m) ; minimum
IN NS localhost.
localhost A 127.0.0.1
@tdittmar
tdittmar / force_tls.cs
Created December 10, 2016 19:55
Force TLS encryption in C#
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12;
@tdittmar
tdittmar / parameterized_top.sql
Created December 10, 2016 18:28
Parameterize the T-SQL TOP clause
CREATE PROCEDURE dbo.sp_TestGetAll
@LIMIT INT
AS
SELECT TOP (@LIMIT) id, col1, col2, col3 FROM TestTable
@tdittmar
tdittmar / paginate.sql
Created December 10, 2016 18:24
Paginate results from a T-SQL query
DECLARE @pageNo INT
DECLARE @pageSize INT
SET @pageNo = 2
SET @pageSize = 15
SELECT
CustomerNo,
FirstName,
LastName
@tdittmar
tdittmar / wpf_listbox_same_column_width.cs
Last active December 10, 2016 18:20
Use same widths for all the columns in a WPF ListBox
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="col1" />
<ColumnDefinition SharedSizeGroup="col2" />
</Grid.ColumnDefinitions>
@tdittmar
tdittmar / transpose_result.sql
Created December 10, 2016 18:09
Turn a result from rows into a comma-separated string
DECLARE @test NVARCHAR(MAX)
SELECT @test = COALESCE(@test + ', ', '') + Field FROM <Sampletable> WHERE <whereclause> AND Field IS NOT NULL
SELECT @test
@tdittmar
tdittmar / passing_object_right.cs
Created December 10, 2016 17:45
Notes about `System.Threading.Timer`
StateObject object = new StateObject();
object.Number = 5;
System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(callback), object, ...);
@tdittmar
tdittmar / nth-row.sql
Created December 9, 2016 09:06
Fetch n-th row from the end of a table in T-SQL
declare @whichRow INT
set @whichRow = 5
select top 1 * from
(
select top (@whichRow) * from <thetable> where <whereclause> order by <orderbyclause> desc
) tmp
order by id asc
@tdittmar
tdittmar / dynamic_object.cs
Last active December 10, 2016 19:30
Creating a dynamic object in C#, for example to serialize it to JSON
dynamic test = new {
id = 12345,
additionalData = new
{
something = "Hello World",
subItems = new List<object>()
{
new {
test1 = "this",
test2 = "is"