Skip to content

Instantly share code, notes, and snippets.

@szunyog
szunyog / mssql_fk_list
Created November 21, 2013 10:11
Lists all foreign keys (source and ref columns) in a MSSQL database.
SELECT
t.name AS TableWithForeignKey,
c.name AS ForeignKeyColumn,
r.name AS ReferencedTable,
rc.name AS ReferencedColumnName
FROM sys.foreign_key_columns AS fk
inner join sys.tables AS t ON fk.parent_object_id = t.object_id
inner join sys.columns AS c ON (t.object_id = c.object_id AND fk.parent_column_id = c.column_id)
inner join sys.tables AS r ON fk.referenced_object_id = r.object_id
inner join sys.columns AS rc ON (r.object_id = rc.object_id AND rc.column_id = fk.referenced_column_id)
@szunyog
szunyog / mssq_killing_other_db_connections
Created December 13, 2013 09:36
Killing other processes connected to an MSSQL database.
declare @db_name varchar(100) = 'dbname';
declare @kill_commands varchar(max) = '';
select
@kill_commands=@kill_commands+'kill '+convert(varchar(5),spid)+';'
from master..sysprocesses
where
spid <> @@SPID -- avoid to kill the current process
and dbid=db_id(@db_name)
@szunyog
szunyog / FileAsyncCopy
Last active June 22, 2022 11:12
Async file copy c#
// Minimal async file copy using background worker
public class FileAsyncCopy
{
private string _source;
private string _target;
BackgroundWorker _worker;
public FileAsyncCopy(string source, string target)
{
if (!File.Exists(source))
@szunyog
szunyog / edmx_navigation_and_scalar_properties
Created June 17, 2014 09:55
Creates a list of the navigation and the belonging scalar properties.
private class Key
{
public string TypeName { get; set; }
public string NavPropertyName { get; set; }
public override string ToString()
{
return string.Format("{0}.{1}", TypeName, NavPropertyName);
}
}
@szunyog
szunyog / cmd_current_dir
Created July 31, 2014 07:31
Getting the directory where your script is located using windows command file
set CURRENT_DIR=%~dp0
echo %CURRENT_DIR%
@szunyog
szunyog / Style
Last active December 16, 2020 10:16
WPF TabControl First, Last TabItem Style
...
<c:TabIndexConverter x:Key="TabIndexConverter" />
<SolidColorBrush x:Key="TabItemSelectedBackground" Color="Gray" />
<SolidColorBrush x:Key="StandardButtonBackground" Color="White" />
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Grid Name="Panel" Height="90">
@szunyog
szunyog / mininal_xsd_documentation_generator
Last active August 29, 2015 14:08
Mininal XSD documentation generator
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/10/XMLSchema-instance"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<BODY>
<xsl:apply-templates select="//xsd:complexType[@name]">
@szunyog
szunyog / add_user_to_system_role
Created January 29, 2015 10:02
CMD script to add a user to the SQL Server sysadmin role
@echo off
rem
rem ****************************************************************************
rem
rem Copyright (c) Microsoft Corporation. All rights reserved.
rem This code is licensed under the Microsoft Public License.
rem THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
rem ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
rem IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
rem PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
@szunyog
szunyog / CheckIfColumnExists
Created February 20, 2015 09:36
sqlite check column exists c#
private bool CheckIfColumnExists(string tableName, string columnName)
{
using(var conn = new SQLiteConnection("Data Source=mydb.sqlite;"))
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = string.Format("PRAGMA table_info({0})", tableName);
var reader = cmd.ExecuteReader();
int nameIndex = reader.GetOrdinal("Name");
@szunyog
szunyog / si7021.py
Created February 9, 2017 16:14 — forked from minyk/si7021.py
Si7021 Sensor Module for Micropython-ESP8266
from time import sleep_ms
from machine import Pin, I2C
# Default Address
SI7021_I2C_DEFAULT_ADDR = 0x40
# Commands
CMD_MEASURE_RELATIVE_HUMIDITY_HOLD_MASTER_MODE = 0xE5
CMD_MEASURE_RELATIVE_HUMIDITY = 0xF5
CMD_MEASURE_TEMPERATURE_HOLD_MASTER_MODE = 0xE3