Skip to content

Instantly share code, notes, and snippets.

View richardkundl's full-sized avatar

Richard Kundl richardkundl

View GitHub Profile
@richardkundl
richardkundl / readme.md
Created February 23, 2015 13:48
Azure-SQL Server toolbelt

Azure-SQL Server toolbelt

@richardkundl
richardkundl / find-col-from-foreignkey.sql
Created February 21, 2015 14:14
Find table and col from foreign key name
SELECT
OBJECT_NAME(f.parent_object_id) TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName
FROM
sys.foreign_keys AS f
INNER JOIN
sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN
sys.tables t
@richardkundl
richardkundl / drop-tables.sql
Last active March 14, 2023 20:04
Drop all tables in a SQL Server database (Azure Friendly!)
-- original source: http://edspencer.me.uk/2013/02/25/drop-all-tables-in-a-sql-server-database-azure-friendly/
-- drop all constraint
while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
begin
declare @sql1 nvarchar(2000)
SELECT TOP 1 @sql1=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
+ '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
FROM information_schema.table_constraints
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
@richardkundl
richardkundl / 10k-common-passwords
Created January 28, 2015 10:22
10000 mostly used passwords
password
123456
12345678
1234
qwerty
12345
dragon
pussy
baseball
football
@richardkundl
richardkundl / MimeTypeLookup.cs
Last active August 29, 2015 14:07 — forked from ChristianWeyer/MimeTypeLookup.cs
Mime type lookup
using System;
using System.Collections.Generic;
using System.IO;
namespace Acme.Infrastructure.Helper
{
public static class MimeTypeLookup
{
private static readonly Dictionary<string, string> _mappings = new Dictionary<string, string>(1500, StringComparer.InvariantCultureIgnoreCase)
{
@richardkundl
richardkundl / azure-db-size.sql
Created October 20, 2014 08:23
Azure SQL database size query
GO
select sum(reserved_page_count) * 8.0 / 1024 AS DbSizeInMB
from sys.dm_db_partition_stats
GO
select sys.objects.name as 'TableName', sum(reserved_page_count) * 8.0 / 1024 as 'Size (in MB)'
from sys.dm_db_partition_stats, sys.objects
where sys.dm_db_partition_stats.object_id = sys.objects.object_id
@richardkundl
richardkundl / _readme.md
Last active November 21, 2016 15:00
AFINN sentiment analysis

AFINN

AFINN is a list of English words rated for valence with an integer between minus five (negative) and plus five (positive). The words have been manually labeled by Finn Årup Nielsen in 2009-2011. The file is tab-separated. There are two versions:

AFINN-111: Newest version with 2477 words and phrases.

More info

###Usage

@richardkundl
richardkundl / shuffle.cs
Created August 20, 2014 18:27
Fisher-Yates algorithm shuffle an array with O(n) time complexity
/// <summary>
/// Fisher-Yates algorithm with O(n) time complexity
/// </summary>
/// <param name="array">array to be shuffled</param>
/// <returns>shuffled array</returns>
public static int[] FisherYates(int[] array)
{
Random r = new Random();
for (int i = array.Length - 1; i > 0; i--)
{
@richardkundl
richardkundl / Common-isEmpty.js
Last active December 20, 2022 20:06
Javascript is empty function
// Current value is empty
this.isEmpty = function(value){
return value == null // NULL value
|| value == undefined // undefined
|| value == 'undefined' // undefined
|| value.length == 0 // Array is empty
|| value == '00000000-0000-0000-0000-000000000000' // Guid empty
|| ((value instanceof Date && !isNaN(value.valueOf())) // Validate DateTime value and check min-max value
&& ((value <= new Date(1753, 01, 01)) // SQL DateTime minimum value
|| (value >= new Date(9999, 12, 31, 23, 59, 59, 999))) // SQL DateTime maximum value
@richardkundl
richardkundl / identicon.html
Last active November 12, 2021 11:28
Github style identicon generator
<html>
<head>
<title>Github style identicon generator </title>
<style>
body { background: #333 }
canvas { margin: 1em }
</style>
<script src="http://www.myersdaily.org/joseph/javascript/md5.js"></script>
</head>
<body>