Skip to content

Instantly share code, notes, and snippets.

View jcorderodr's full-sized avatar

J Cordero jcorderodr

View GitHub Profile
@jcorderodr
jcorderodr / objects-removal.sql
Created October 13, 2023 01:28
Remove all db objects + system-versioned tables [Azure Databases compatible]
DECLARE @sql NVARCHAR(2000)
WHILE(EXISTS(SELECT 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE='FOREIGN KEY'))
BEGIN
SELECT TOP 1 @sql=('ALTER TABLE ' + CONSTRAINT_SCHEMA + '.[' + TABLE_NAME + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
EXEC(@sql)
PRINT @sql
END
@jcorderodr
jcorderodr / ADUserProperty.cs
Last active July 13, 2021 00:18
ActiveDirectory Basic Management on C#
using System;
//Class from: http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/all-operations-on-active-directory-ad-using-C-Sharp/
namespace TestAD.ActiveDirectory
{
class ADUserProperty
{
public const String DESCRIPTION = "description";
@jcorderodr
jcorderodr / PackageManager.cs
Created November 7, 2017 15:31
System Center 2010 PackageManager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.ConnectorFramework;
namespace SCSMTool.Framework
@jcorderodr
jcorderodr / script.js
Created July 28, 2017 00:47
Comparision between two ko.observableArray
self.originalValues = ko.observableArray([]);
self.modifiedValues = ko.observableArray(self.originalValues.slice());
//...
// user modified the self.modifiedValues() object interacting with the UI so now, we want to know the missing items
var marked = [];
ko.utils.arrayForEach(self.originalValues(), function (original) {
var exists = ko.utils.arrayFirst(self.modifiedValues(), function (item) {
@jcorderodr
jcorderodr / XController.cs
Created July 28, 2017 00:44
Get/Set User Browser Language C# - ASP.NET MVC (Razor)
// This final block, in your controller.
public const string SessionLangKey = "UsrLang";
public ActionResult Language(string lang, string returnUrl)
{
if (String.IsNullOrWhiteSpace(lang)) View("Index");
switch (lang.ToLower())
{
case "en-EN":
case "es-ES":
@jcorderodr
jcorderodr / HotKey.cs
Created July 28, 2017 00:42
C# .NET Hot Key
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312)
{
//TODO: action here.
@jcorderodr
jcorderodr / Program.cs
Created July 28, 2017 00:41
Set ToolStripItem & ToolStripMenuItem Visibility C#
private void SetVisibleProperty(bool visible = false, params ToolStripItem[] controls)
{
foreach (var ctrl in controls)
{
ctrl.Enabled = visible;
if (ctrl is System.Windows.Forms.ToolStripMenuItem)
{
var menu = ctrl as System.Windows.Forms.ToolStripMenuItem;
if (menu.DropDownItems.Count > 0)
{
@jcorderodr
jcorderodr / script.sql
Created July 28, 2017 00:40
MSSQL - Change Tracking Scripts
-- To know wich tables are Tracking enable
SELECT sys.schemas.name as Schema_name, sys.tables.name as Table_name FROM sys.change_tracking_tables
JOIN sys.tables on sys.tables.object_id = sys.change_tracking_tables.object_id
JOIN sys.schemas on sys.schemas.schema_id = sys.tables.schema_id
--Enable Tracking on 'abc' table
ALTER TABLE dbo.abc ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF)
-- More info: https://msdn.microsoft.com/en-us/library/bb933875%28v=sql.105%29.aspx
@jcorderodr
jcorderodr / Program.cs
Created July 28, 2017 00:39
Call External Windows from C#
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using MainApplication.Service;
namespace MainApplication
{
static class Program
@jcorderodr
jcorderodr / script.sql
Created July 28, 2017 00:38
Select Random rows with T-SQL (MSSQL)
SELECT * FROM dbo.[TablaName] WHERE (ABS(CAST((BINARY_CHECKSUM(*) * RAND()) as int)) % 100) < 10
-- Will select the half of rows
SELECT TOP 50 PERCENT * FROM dbo.[TablaName] Order By NewId()
-- MSDN Article: https://msdn.microsoft.com/en-us/library/cc441928.aspx