Skip to content

Instantly share code, notes, and snippets.

View chinhvo's full-sized avatar

Chinh Vo Wili chinhvo

View GitHub Profile
@chinhvo
chinhvo / types.ts
Created March 27, 2024 06:55 — forked from bkwhite/types.ts
/**
* Methods required by a custom player for `react-player`
*/
export interface Player {
load(url?: string): void;
seekTo(amount: number, type?: 'seconds' | 'fraction'): void;
getCurrentTime(): number;
getDuration(): number;
getSecondsLoaded(): number | null;
stop?(): void;
import React, { Component } from "react";
import ReactPlayer, { ReactPlayerProps } from "react-player";
import { getSDK } from "react-player/lib/utils";
import {
Player,
IkWidget,
KalturaNotificationName,
KalturaPlayerElement,
KalturaPlayerEvents,
@chinhvo
chinhvo / check-if-valid-url.php
Created March 20, 2024 08:00 — forked from thagxt/check-if-valid-url.php
check if url is valid
<?php
/* @ http://stackoverflow.com/a/12628971 */
function isValidUrl($url){
// first do some quick sanity checks:
if(!$url || !is_string($url)){
return false;
}
// quick check url is roughly a valid http request: ( http://blah/... )
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){
return false;
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);
@chinhvo
chinhvo / upload_azure_blob_sas.js
Created January 18, 2024 07:23 — forked from tomconte/upload_azure_blob_sas.js
Upload a Blob to Azure Storage using Shared Access Signatures (SAS) in Node.JS
var fs = require('fs');
var https = require('https');
var blob_host = 'tconeu.blob.core.windows.net';
var blob_container = 'tessel-uploads';
// Use any tool to generate a Shared Access Key e.g. Azure Management Studio
var blob_sas = '?sr=c&sv=2014-02-14&si=tessel&sig=xxxxRv%2xxxxUTd8xxxxMKc0xxxxi%2Fxxxxw6VsxxxxGjdJxxxx';
var blob_name = 'test.jpg';
@chinhvo
chinhvo / RouteIndicator.js
Created November 29, 2023 11:34 — forked from jaydenseric/RouteIndicator.js
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();
request
response
app
req
res
originalUrl
state
_i18n
matched
router
/**
* Validates hex value
* @param {String} color hex color value
* @return {Boolean}
*/
function isValidHex(color) {
if(!color || typeof color !== 'string') return false;
// Validate hex values
if(color.substring(0, 1) === '#') color = color.substring(1);
@chinhvo
chinhvo / Startup.cs
Created August 21, 2023 02:43 — forked from shubhamnikam/Startup.cs
Setup HttpClient configuration in Startup.ConfigureService
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
//configure httpclient service
services.AddHttpClient("GithubAPI", client=>
{
//customize as per your need
client.BaseAddress = new Uri("http://api.github.com/");
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
@chinhvo
chinhvo / GithubController.cs
Created August 21, 2023 02:43 — forked from shubhamnikam/GithubController.cs
Named Client implementation of IHttpClientFactory
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace TestAPIGithub.Controllers
{