Skip to content

Instantly share code, notes, and snippets.

@yzorg
yzorg / trycatchtran.sql
Last active June 19, 2020 12:58 — forked from mishrsud/trycatchtran.sql
SQL TRY-CATCH WITH TRANSACTION
CREATE PROCEDURE [dbo].[spTxnDemo]
@debug int = NULL
, @forceError int = NULL
AS
BEGIN
SET NOCOUNT ON;
SET @debug = ISNULL(@debug, 0);
SET @forceError = ISNULL(@forceError, 0);
BEGIN TRY
BEGIN TRANSACTION MY_TXN;
@yzorg
yzorg / libman.json
Last active October 18, 2019 16:09
libman.json
{
"version": "1.0",
"defaultProvider": "cdnjs",
"defaultDestination": "wwwroot/lib",
"libraries": [
{
"provider": "jsdelivr",
"library": "bootstrap@4.3.1",
"destination": "wwwroot/lib/bootstrap/",
"files": [
@yzorg
yzorg / CustomConvert-XlsxToCsv.ps1
Created August 20, 2019 19:16
my take on convert .xlsx to .CSV in Powershell using Excel COM (Windows only)
$step = ''
function CustomConvert-XlsxToCsv
{
param(
[Parameter(Mandatory)]$XlsxFile,
[string]$Sheet = 'Sheet1',
[string]$CsvFile,
[switch]$Test
)
@yzorg
yzorg / sql-snippet-filename-from-path.sql
Last active June 7, 2019 14:45
Convert full path to filename.
-- Convert full path to filename.
-- i.e. \\mycompany.com\bigshare\apps\MyApp\outbound\ClientID\ReportType.ClientID.20190529.csv
-- to ReportType.ClientID.20190529.csv
DECLARE @searchFromRight VARCHAR(MAX) = REVERSE(@filename);
DECLARE @pathCharIndex BIGINT = COALESCE(CHARINDEX('\', @searchFromRight), CHARINDEX('/', @searchFromRight), 0);
--IF NOT (@pathCharIndex BETWEEN 27 AND 60)
-- THROW 51000, 'Could not convert full path to filename.', 1;
SET @filename = SUBSTRING(@filename, LEN(@filename) - @pathCharIndex + 2, @pathCharIndex - 1)
// Sample code comes from Humanizer Git Home
// https://github.com/MehdiK/Humanizer
using System;
using Humanizer;
public class Program
{
public static void Main()
{
WriteInOut("\"Underscored_input_String_is_turned_INTO_sentence\".Humanize()", "Underscored_input_String_is_turned_INTO_sentence".Humanize());
@yzorg
yzorg / PointsLines.cs
Created July 19, 2018 22:16
programming coda: detect points on a line
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
//## Output
// starting PointsLines
//m:-1 b:5 has points:
// X:1.00 Y:04
// X:3.00 Y:02

I'd like to summarize status of the "spread object merge" ES feature, in browsers, and in the ecosystem via tools.

Spec

Browsers: in Chrome, in SF, Firefox soon (ver 60, IIUC)

  • Browser support for "spread properties" [shipped in Chrome 60][1], including this scenario.
@yzorg
yzorg / BundleConfig.cs
Last active March 31, 2018 17:02
ASP.NET 4.x: use WebPack asset-manifest.json in BundleConfig.cs
using System.Web.Optimization;
using Newtonsoft.Json.Linq;
namespace MyMvc5App
{
public class BundleConfig
{
public const string ReactInputPrice = "~/bundles/reactInputPrice";
public static void RegisterBundles(BundleCollection bundles)
@yzorg
yzorg / MigrationBuilderExtensions.cs
Created January 4, 2018 20:47
Entity Framework Core migration tools: run a .sql script and `DropStoredProcedureIfExists()`
using System;
using System.IO;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Yzorg.EFCore.Migrations
{
internal static class MigrationBuilderExtensions
{
/// <summary>
/// Only works for `dbo` schema.
USE [MyAppDatabase]
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND OBJECT_ID = OBJECT_ID('dbo.spAppUserSave'))
EXEC('CREATE PROCEDURE [dbo].[spAppUserSave] AS BEGIN SET NOCOUNT ON; /* invalid empty SPROC */ END')
GO
SET ANSI_NULLS OFF
SET QUOTED_IDENTIFIER OFF
GO
-- Author: Chris Tracy
ALTER PROCEDURE [dbo].[spAppUserSave]