Skip to content

Instantly share code, notes, and snippets.

@shinkathe
shinkathe / sample.tsx
Created September 27, 2022 16:22
Sample usage of useclient
export const MovieList = ({listId}: {listId: string}) => {
const [moviesList, setMoviesList] = useState<Movie[]>();
const { loading: loadingMovies } = useFetch<Movie[], unknown>(
request(`api/movies/${listId}`),
[listId],
{
when: () => listId != undefined,
onSuccessEffect: setMoviesList
}
@shinkathe
shinkathe / useClient.ts
Created September 27, 2022 16:01
useClient hook that handles cancellations automatically
import {
DependencyList,
useEffect,
useCallback,
useState,
useMemo,
} from "react";
import * as R from "ramda";
import { attemptP, fork, FutureInstance } from "fluture";
@shinkathe
shinkathe / ClamAV.cs
Last active September 27, 2023 04:41
using nClam;
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Extensions.Logging;
using Azure.Storage.Blobs;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Linq;
// ##### RUN AV ON FILE #####
log.LogInformation("Download completed. Connecting to AV server {ClamAVServerUrl}:{ClamAVServerPort}... ", ClamAVServerUrl, ClamAVServerPort);
var clam = new ClamClient(ClamAVServerUrl, ClamAVServerPort);
bool isConnected = await clam.PingAsync();
var version = await clam.GetVersionAsync();
if (!isConnected) throw new Exception("AV server connection could not be established.");
log.LogInformation("Connection ok: {IsConnected}. AV server reports version: {ServerVersion}", isConnected, version);
// ##### READ EVENT GRID EVENT FROM REQUEST #####
log.LogInformation("Begin handling request. {EventGridEvent}", eventGridEvent.Data);
if (!TryGetEventData<string>(eventGridEvent, CREATED_EVENT_URL, out var url))
{
log.LogError("EventData could not be parsed. UrlFound check failed.");
return;
}
// ##### READ FILE NAME AND STORAGE ACCOUNT CONTAINER NAME FROM EVENT GRID EVENT
[FunctionName("RunAvOnFileUploaded")]
public static async Task Run([EventGridTrigger] Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, ILogger log)
{
// ***
}
@shinkathe
shinkathe / EnableRewindRepro.cs
Created May 29, 2018 13:39
EnableRewind + StatusCodesPagesWithReExecute
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
@shinkathe
shinkathe / Settings.cs
Created February 21, 2018 15:33
Application allows for smart defaults
public string DbConnectionString => Environment.GetEnvironmentVariable("DB_CONNECTIONSTRING")
?? _configuration.GetConnectionString("DB_CONNECTIONSTRING")
?? "DevelopmentEnvironmentConnectionString";
public string BasicAuthUserName => Environment.GetEnvironmentVariable("BASICAUTH_USERNAME")
?? _configuration["BasicAuth:Username"]
?? "admin";
@shinkathe
shinkathe / launchSettings.json
Last active February 21, 2018 15:31
We can run our app in different modes
"Staging": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5005",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging",
"API_USERNAME": "admin",
"API_PASSWORD": "test123",
"DB_CONNECTIONSTRING": "Data Source=SERVER;Initial Catalog=DBName;User ID=username;Password=password;"
@shinkathe
shinkathe / ExecutableFixture.cs
Created February 21, 2018 14:41
Test should run it's own version of an executable
public class ExecutableFixture : IDisposable
{
private Process _process;
private bool _isDevelopment;
public ExecutableFixture()
{
var executableRootPath = "../../../../APIProject/bin/Debug/netcoreapp1.1/";
_isDevelopment = File.Exists($"{executableRootPath}APIProject.dll");