Skip to content

Instantly share code, notes, and snippets.

View chinhvo's full-sized avatar

Chinh Vo Wili chinhvo

View GitHub Profile
@FWest98
FWest98 / ConditionalValidationAttribute.cs
Created April 6, 2020 22:12
.NET Core 3 Conditional Model Validation Attribute
using System;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
namespace Foo {
// Implementation makes use of the IPropertyValidationFilter interface that allows
// control over whether the attribute (and its children, if relevant) need to be
// validated.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class ConditionalValidationAttribute : Attribute, IPropertyValidationFilter {
public string OtherProperty { get; set; }
@luan0ap
luan0ap / streamToBase64.js
Created January 9, 2020 17:42
Convert a readable stream to base64 string
/**
* Convert a Readable Stream to base64 string
* @param {ReadableStream} stream - a readable stream to convert in base64 string
* @returns {Promise} - Promise that resolve in a string containing the base64
*/
const streamToBase64 = (stream) => {
const concat = require('concat-stream')
const { Base64Encode } = require('base64-stream')
return new Promise((resolve, reject) => {
@Jonarod
Jonarod / blob_conversions_util.js
Created December 7, 2019 04:56
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based.
const BlobToBase64 = function(blob){
let blobUrl = URL.createObjectURL(blob);
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = err => reject(err);
img.src = blobUrl;
}).then(img => {
URL.revokeObjectURL(blobUrl);
@GetoXs
GetoXs / ServiceCollectionExtentions.cs
Last active March 2, 2024 06:06
Register All Types (with Generic) in .NET Core DependencyInjection
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
public static class ServiceCollectionExtentions
{
public static void AddAllTypes<T>(this IServiceCollection services
, Assembly[] assemblies
, bool additionalRegisterTypesByThemself = false
@mykeels
mykeels / RsaKeyService.cs
Last active January 26, 2024 03:47
For IdentityServer4's AddSigningCredentials in production
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.IdentityModel.Tokens;
@KempfCreative
KempfCreative / ctx methods and properties
Last active November 8, 2023 08:30
Strapi ctx internals
request
response
app
req
res
originalUrl
state
_i18n
matched
router
/*
*ngFor="let c of oneDimArray | sortBy:'asc'"
*ngFor="let c of arrayOfObjects | sortBy:'asc':'propertyName'"
*/
import { Pipe, PipeTransform } from '@angular/core';
import { orderBy } from 'lodash';
@Pipe({ name: 'sortBy' })
export class SortByPipe implements PipeTransform {
@jaydenseric
jaydenseric / RouteIndicator.js
Last active November 29, 2023 11:34
A route change indicator for Next.js using React hooks.
import classNameProp from 'class-name-prop';
import { useRouter } from 'next/router';
import React from 'react';
import styles from './RouteIndicator.module.css';
const DONE_DURATION = 250;
export default function RouteIndicator() {
const router = useRouter();
@JaimeStill
JaimeStill / readme.md
Last active August 23, 2024 16:07
FormData Uploads in ASP.NET Core and Angular

Walkthrough Uploading FormData with Angular

For an example application that integrates this process, see my FullstackOverview repo on GitHub. The code in this example is taken directly from this app.

upload-demo

File Upload Component

This component allows you have a custom styled file upload element.

@darrenmothersele
darrenmothersele / drop-zone-directive.ts
Last active July 12, 2024 13:05
Angular Drag and Drop File Directive
import { Directive, EventEmitter, HostBinding, HostListener, Input, Output } from '@angular/core';
// Angular Drag and Drop File
//
// Add this directive to an element to turn it into a dropzone
// for drag and drop of files.
// Example:
//
// <div (appDropZone)="onDrop($event)"></div>
//