Skip to content

Instantly share code, notes, and snippets.

View ozkary's full-sized avatar
🎯
Focusing on the next reality to come

Oscar D. Garcia ozkary

🎯
Focusing on the next reality to come
View GitHub Profile
@ozkary
ozkary / main.cs
Last active June 21, 2019 21:51
Single JOIN multi statement with embedded SQL Use it when there is no access to create views on the database which is the preferred approach.
static void Main(string[] args)
{
Console.WriteLine("Running a simple multi join statement on EF!");
var connection = @"Server=.\sqlexpress;Database=dev;Trusted_Connection=True;ConnectRetryCount=0";
var optionsBuilder = new DbContextOptionsBuilder<TaskContext>();
optionsBuilder.UseSqlServer(connection);
using (TaskContext context = new TaskContext(optionsBuilder.Options))
@ozkary
ozkary / AuthWebViewClient
Created December 6, 2018 15:37
In order to write a handler for the challenge-response event, we need to extend the WebViewClient class. We start by implementing a constructor that can take the credential information. This enables the activity that instantiates our class to manage the credential information and just pass it to our class during the class instantiation.
internal class AuthWebViewClient : WebViewClient
{
public string Username { get; }
public string Password { get; }
private int LoginCount = 0;
/// <summary>
/// gets the user credentials for the impersonation process
/// </summary>
/// <param name="username"></param>
@ozkary
ozkary / powershell-sharepoint-invoke-restmethod.ps1
Created June 21, 2019 21:47
With PowerShell, we can use the invoke-RestMethod cmdlet to make Restful API calls to get JSON data. When using the SharePoint Restful APIs, the cmdlet returns the JSON data in string format which is not the intended result.
#set the headers content type
$contentType = 'application/json;odata=verbose'
$headers = @{}
$headers["Accept"] = $contentType
$headers["Content-Type"] = $contentType
$uri = "ozkary.sharepoint.com/GetByTitle('LIST-NAME')/items"
$data = Invoke-RestMethod -Method GET -Uri $uri -UseDefaultCredentials -Headers $headers
@ozkary
ozkary / interopdemo.cs
Created July 9, 2019 00:38
Console application to show how to use DLLImport to import methods exposed by an unmanaged dynamic-link library (DLL). This example shows how to call the MessageBox Win32 API Call.
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
import { ClientRequest} from "http";
import http = require("https");
/**
* https request class in typesript to show how to manage errors and events
* to help prevent ECONNRESET errors
*/
export class HttpRequest {
public async send(options: http.RequestOptions, data?: any): Promise<any> {
/*
Filename: azure-sql-read-only-user.sql
Purpose: Create a read-only login user on a target database to enable the access to the data, but disable any insert, update, delete operations.
Author:
Oscar Garcia @ozkary
Reference:
@ozkary
ozkary / Azure-static-web-app-cli
Last active March 22, 2022 14:38
CLI Script to create Azure Static Wep App Resource
#!/bin/bash
#
# Purpose: Use the bash file to automate the creation of an Azure Static Web App with CICD Github Pipeline
# Requirements: Azure subscription, Github branch and repo token
# Author: 0garcia - ozkary
# Article: https://www.ozkary.com/2021/02/azure-static-web-app-github-actions-cicd.html
#
clear
# creates the azure resources for a static web app with github cicd pipeline
@ozkary
ozkary / logger-component-error.ts
Last active March 22, 2022 14:39
AppInsights React Logger Service
// import the operations from logger
import { error, audit } from '../logger';
/**
* Sample code to log an error from a handled exception
* send the message asychronously
*/
try {
// call an operation that can raise errors
@ozkary
ozkary / continent-names.xml
Last active October 22, 2021 16:04
API Management transforms a SOAP API into JSON API
<policies>
<inbound>
<base />
<rewrite-uri template="/websamples.countryinfo/CountryInfoService.wso" copy-unmatched-params="false" />
<set-body template="liquid">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns="http://www.oorsprong.org/websamples.countryinfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ListOfContinentsByName>
</ListOfContinentsByName>
</soap:Body>
@ozkary
ozkary / routeLoader.ts
Last active March 22, 2022 14:44
Route loader when using lazy loading and dynamic imports to manage ChunkLoadErrors
/**
* @file routes/routeLoader.ts
* @description lazy loading of routes.
*
* @author ogarcia (ozkary)
*
*/
/**
* Use this route loader when using lazy loading and dynamic imports