Skip to content

Instantly share code, notes, and snippets.

@yngwie74
yngwie74 / spwho_loop.sql
Created November 7, 2012 21:48
sp_who2 con timer
DECLARE @table TABLE
(
SPID INT
,Status VARCHAR(15)
,[Login] VARCHAR(30)
,HostName VARCHAR(MAX)
,BlkBy VARCHAR(10)
,DBName VARCHAR(15)
,Command VARCHAR(MAX)
,CPUTime INT
@yngwie74
yngwie74 / GetDicts.cs
Created October 11, 2012 22:56
Generar un diccionario directamente desde una consulta linq
// forma tradicional, agregando los elementos uno a uno
private IDictionary<int, DateTime> GetDiccionaryOriginal(int[] keys)
{
var result = new Dictionary<int, DateTime>();
using (var context = DataContextFactory.MyContext)
{
context.MY_RECORDs.Where(r => keys.Contains(r.RECORD_ID))
.ToList()
.ForEach(r => result.Add(r.RECORD_ID, r.LATEST_UPDATE_TS));
@yngwie74
yngwie74 / gist:3380963
Created August 17, 2012 17:47
Determinar la fecha de última modificación a la estructura de una tabla en SQL Server
SELECT name
,create_date
,modify_date
FROM sys.tables
WHERE name = 'TABLE_NAME'
@yngwie74
yngwie74 / gist:3380899
Created August 17, 2012 17:40
Determinar cuando se hizo un "RESTORE" a un BD por última vez en SQL Server
SELECT rsh.destination_database_name AS [Database]
,rsh.user_name AS [Restaurado por]
,CASE
WHEN rsh.restore_type = 'D' THEN 'Database'
WHEN rsh.restore_type = 'F' THEN 'File'
WHEN rsh.restore_type = 'G' THEN 'Filegroup'
WHEN rsh.restore_type = 'I' THEN 'Differential'
WHEN rsh.restore_type = 'L' THEN 'Log'
WHEN rsh.restore_type = 'V' THEN 'Verifyonly'
WHEN rsh.restore_type = 'R' THEN 'Revert'
@yngwie74
yngwie74 / gist:3315444
Created August 10, 2012 16:39
Midiendo de forma precisa el performance del código
using System.Diagnostics;
class MiClase
{
private void MiFuncion()
{
var sw = new Stopwatch();
sw.Start();
// Tu código va aquí
@yngwie74
yngwie74 / gist:3144879
Created July 19, 2012 15:54
Obtener un log del SQL generado por un DataContext
private TRet WithLogging<T, TRet>(T context, string logmsg, Func<T, TRet> func) where T : DataContext
{
TRet result;
var log = context.Log;
var builder = new StringBuilder();
try
{
context.Log = new StringWriter(builder);
@yngwie74
yngwie74 / LCD.cs
Created March 12, 2012 23:46
LCD numbers kata (C#)
using System.Collections.Generic;
using System.Linq;
namespace ViveCodigo.Katas.LCD
{
/// <summary>
/// Basado en la idea original de @rodrigo_salado
/// </summary>
public class LCD
{
@yngwie74
yngwie74 / LCDTest.cs
Created March 12, 2012 23:42
LCD numbers' tests (C#)
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ViveCodigo.Katas.LCD.Test
{
/// <summary>
///This is a test class for LCDTest and is intended to contain all its Unit Tests.
///</summary>
[TestClass]
public class LCDTest
{
@yngwie74
yngwie74 / LCD.java
Created March 12, 2012 23:40
LCD numbers kata (java)
package org.vivecodigo.katas.lcd;
import java.util.*;
public class LCD {
private static final String _NONE = " ";
private static final String _LEFT = " |";
private static final String _MIDL = " _ ";
private static final String _MDLT = " _|";
@yngwie74
yngwie74 / AllTests.java
Created March 12, 2012 23:38
LCD numbers' tests (java)
package org.vivecodigo.katas.lcd;
import static junit.framework.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses( { AllTests.TestUtils.class, AllTests.LCDTests.class })