Skip to content

Instantly share code, notes, and snippets.

View chinhvo's full-sized avatar

Chinh Vo chinhvo

  • Ho Chi Minh City
View GitHub Profile
const fs = require("fs");
const path = require("path");
function fixFile(filepath) {
const contents = fs.readFileSync(filepath, "utf-8");
const matcher = /([0-9]+(?:\.[0-9]+)?)rem/igm;
const result = contents.replaceAll(matcher, (substr, size) => {
const rem = Number(size);
@redatawfik
redatawfik / server.cpp
Created June 12, 2020 03:52
Server implementation of client-server chat using Winsock
#include <winsock2.h>
#include <iostream>
struct CLIENT_INFO {
SOCKET hClientSocket;
struct sockaddr_in clientAddr;
};
char szServerIPAddr[] = "192.168.1.4"; // Put here the IP address of the server
int nServerPort = 5050; // The server port that will be used by
@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 April 7, 2026 13:16
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();