Skip to content

Instantly share code, notes, and snippets.

View daltonnyx's full-sized avatar
🦥

Quy Truong daltonnyx

🦥
  • Saigon Technology
  • Da Nang
View GitHub Profile
@daltonnyx
daltonnyx / NoINotifyCreateWebHostBuilder_dotnetcore-2.x
Created February 13, 2020 12:14 — forked from babakontheweb/NoINotifyCreateWebHostBuilder_dotnetcore-2.x
A copy of Microsoft's WebHost.CreateDefaultBuilder but with IIS and FileWatcher dependencies removed for Linux environments. See https://github.com/aspnet/MetaPackages/blob/dev/src/Microsoft.AspNetCore/WebHost.cs#L148
/// <summary>
/// Initializes a new instance of the <see cref="WebHostBuilder"/> class with pre-configured defaults.
/// </summary>
/// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,
/// load <see cref="IConfiguration"/> from environment variables,
+graph;net_graphproportionalfont "0"
cl_crosshairalpha "200";cl_crosshaircolor "4";cl_crosshaircolor_b "50";cl_crosshaircolor_r "50";cl_crosshaircolor_g "250";cl_crosshairdot "1";cl_crosshairgap "-1";cl_crosshairsize "2";cl_crosshairstyle "2";cl_crosshairusealpha "1";cl_crosshairthickness "1";cl_fixedcrosshairgap "-1";cl_crosshair_outlinethickness "0";cl_crosshair_drawoutline "1";
@daltonnyx
daltonnyx / AuthorizationHandler.cs
Created November 13, 2019 16:22
Custom Redirect for Authorization Policy Failure in .Net Core 2.1
Hello everyone, I spent a good deal of time on this problem yesterday and wanted to share my solution as it might help others and also if someone else has a better way of doing this.
Problem: Need a custom redirect for an Authorization Policy Failure (Claims in my case). Do not want to go to default "Access Denied" page.
Why: In my case, I am building a SAAS application and storing a user's monthly expiration time in a claim. For example, if you sign up today, your access is good for 1 month. For every month you renew your subscription, 1 month is added to that "expiration date" claim. Every time you access the application, I check whether the user's access has expired or not. If their access has expired, I want to redirect to the Renewal page, instead of the Access Denied page.
Solution: After searching through the docs: I came across this: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.1
This gets you started on how Authorization Policies work and how to c
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/quytruong/.oh-my-zsh
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
export PATH="$HOME/.composer/vendor/bin:/usr/local/sbin:$PATH"
const getInRangedValue = function(value, min, max) {
return value < min ? min : value > max ? max : value;
}
const pagination = function(current, visible, total) {
const middle = Math.ceil(visible / 2);
let startPage = current - middle + 1, endPage = startPage + visible;
startPage = getInRangedValue(startPage, 1, total - visible + 1);
endPage = getInRangedValue(endPage, visible, total);
let pages = [];
for(let i = startPage; i <= endPage && pages.length < visible; i++) {
@daltonnyx
daltonnyx / MySQL_macOS_Sierra.md
Created March 29, 2018 19:31 — forked from nrollr/MySQL_macOS_Sierra.md
Install MySQL on Sierra using Homebrew

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :

1. Stop mysql:
systemctl stop mysqld
2. Set the mySQL environment option
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
3. Start mysql usig the options you just set
systemctl start mysqld
4. Login as root
//https://stackoverflow.com/questions/28772212/stun-turn-server-connectivity-test
function checkTURNServer(turnConfig, timeout){
return new Promise(function(resolve, reject){
setTimeout(function(){
if(promiseResolved) return;
resolve(false);
promiseResolved = true;
}, timeout || 5000);
/*Horizontal*/
background-image: linear-gradient(to right, black 33%, rgba(255,255,255,0) 0%);
background-position: bottom;
background-size: 3px 1px;
background-repeat: repeat-x;
@daltonnyx
daltonnyx / gist:97fad31b0bd5f034deca73ccd86a922d
Created September 18, 2017 11:55 — forked from ichord/gist:9808444
demo of using pdf.js to extract pages to images
<script src="http://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.1/processing-api.min.js"></script><html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/pdfjs-helloworld-v2/8598/edit
-->
<body>
<canvas id="the-canvas" style="border:1px solid black"></canvas>
<input id='pdf' type='file'/>
<!-- Use latest PDF.js build from Github -->