Skip to content

Instantly share code, notes, and snippets.

View FrankDeGroot's full-sized avatar

Frank de Groot - Schouten FrankDeGroot

View GitHub Profile
@FrankDeGroot
FrankDeGroot / ssh.sh
Last active December 26, 2015 05:09
Some shell commands to enable ssh
# Enable RSA/Public Key Autentication (or default?)
# Disable Password Authentication
sudo vi /etc/ssh/sshd_config
# Set proper privileges on ssh artifacts
cd ~
chmod u-w ~
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
@FrankDeGroot
FrankDeGroot / samba.sh
Last active June 1, 2024 14:44
Some shell commands to enable samba.
#install samba
sudo yum install samba
sudo yum install samba-client
#set workgroup
sudo vi /etc/samba/smb.conf
#set hostname
sudo hostnamectl set-hostname frankg --static
sudo service restart network
@FrankDeGroot
FrankDeGroot / gen.sql
Created September 25, 2013 11:06
Generate max 2^32 rows with a unique number.
with a(n) as (select 0 union all select 1),
b(n) as (select 2*x.n+y.n from a x, a y),
c(n) as (select 4*x.n+y.n from b x, b y),
d(n) as (select 16*x.n+y.n from c x, c y),
e(n) as (select 256*x.n+y.n from d x, d y),
f(n) as (select 65536*x.n+y.n from e x, e y)
select top 100000000 n from f
@FrankDeGroot
FrankDeGroot / sqlxml.ps1
Last active December 23, 2015 19:39
Compare database table with XML contents. Kept for code that extracts parameters from a query string, adds them to a SqlCommand and copies values from variables with the same name.
$cn = new-object Data.SqlClient.SqlConnection 'Server=.;Database=CIA;Trusted_Connection=true'
$cn.open()
$q = @'
select count(*) from journaalposten.unv_conversierekeningschema
where grootboeksysteem='QIS' and maatschappij=@m and gb_rekening=@gbr and kostenplaats=@kp and kostendrager=@kd
'@
$cm = new-object Data.SqlClient.SqlCommand -a $q, $cn
$p = $cm.parameters
@FrankDeGroot
FrankDeGroot / eav.fsx
Created September 24, 2013 12:25
Experiment with entity/attribute/value table in SQL Server using F# script.
open System
open System.Data
open System.Data.Common
let exec exec sql =
let factory = DbProviderFactories.GetFactory("System.Data.SqlClient")
use connection = factory.CreateConnection()
connection.ConnectionString <- "Data Source=.;Initial Catalog=tempdb;Integrated Security=SSPI"
connection.Open()
use command = factory.CreateCommand()
@FrankDeGroot
FrankDeGroot / VSAllCaps.reg
Created September 24, 2013 12:23
Disable/Enable all caps menu items in Visual Studio.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General]
"SuppressUppercaseConversion "=dword:00000001
@FrankDeGroot
FrankDeGroot / SqlExceptionHandler.cs
Created September 24, 2013 12:20
Reverse-formats SQL Server error message: SQL Server formats a template error message inserting table/column/index/etc. names. This code extracts those inserted names. This allows you to detect what table/column/index/etc. is causing trouble. Use this e.g. to detect attempts to insert non-unique values governed by a unique index without first ha…
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;
namespace Company.Product
{
using ModelTableAdapters;
@FrankDeGroot
FrankDeGroot / DataReaderStream.cs
Created September 24, 2013 12:15
Open IDataReader result column as stream using IDataReader.GetBytes.
using System;
using System.Data;
using System.IO;
namespace Company.Product
{
internal class DataReaderStream : Stream
{
private long _position = 0L;
private readonly IDataReader _reader;
@FrankDeGroot
FrankDeGroot / comparelogs.ps1
Last active December 23, 2015 19:39
Compare Endeavour build server result with local build result with SourceGear DiffMerge. Compares with latest result on build server.
filter Get-LastChildItem { Join-Path $_ (gci $_ -Name | sort | select -Last 1) }
$Outs = 'C:\(ProductName)\Branch\99 - bin\Deliverables\Name\Log\Compile\Compile_result.xml',
"$('\\portal\DailyBuildResult\ProductName\Branch' | Get-LastChildItem | Get-LastChildItem)\CIName\Compile\compile.log" | % {
([xml](gc $_)).results.message |
where {$_.type -eq 'warning'} |
sort -CaseSensitive '#text' |
% {"<message>$($_.'#text')</message>"} |
Out-File ($Out = [IO.Path]::GetTempFileName())
$Out
}
@FrankDeGroot
FrankDeGroot / checkfilelock.cs
Created September 24, 2013 12:11
Check if IOException is caused by a file lock.
private static bool IsFileLocked(IOException exception)
{
int errorCode = Marshal.GetHRForException(exception) & ((1 << 16) - 1);
return errorCode == 32 || errorCode == 33;
}