Skip to content

Instantly share code, notes, and snippets.

Thorsten Dittmar tdittmar

View GitHub Profile
@tdittmar
tdittmar / force_tls.cs
Created Dec 10, 2016
Force TLS encryption in C#
View force_tls.cs
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12;
@tdittmar
tdittmar / parameterized_top.sql
Created Dec 10, 2016
Parameterize the T-SQL TOP clause
View parameterized_top.sql
CREATE PROCEDURE dbo.sp_TestGetAll
@LIMIT INT
AS
SELECT TOP (@LIMIT) id, col1, col2, col3 FROM TestTable
@tdittmar
tdittmar / paginate.sql
Created Dec 10, 2016
Paginate results from a T-SQL query
View paginate.sql
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 Dec 10, 2016
Use same widths for all the columns in a WPF ListBox
View wpf_listbox_same_column_width.cs
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="col1" />
<ColumnDefinition SharedSizeGroup="col2" />
</Grid.ColumnDefinitions>
@tdittmar
tdittmar / transpose_result.sql
Created Dec 10, 2016
Turn a result from rows into a comma-separated string
View transpose_result.sql
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 Dec 10, 2016
Notes about `System.Threading.Timer`
View passing_object_right.cs
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 Dec 9, 2016
Fetch n-th row from the end of a table in T-SQL
View nth-row.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 Dec 10, 2016
Creating a dynamic object in C#, for example to serialize it to JSON
View dynamic_object.cs
dynamic test = new {
id = 12345,
additionalData = new
{
something = "Hello World",
subItems = new List<object>()
{
new {
test1 = "this",
test2 = "is"
You can’t perform that action at this time.