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 / git.migrate
Created June 30, 2021 08:39 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@daltonnyx
daltonnyx / reset-commit-author.md
Created January 26, 2021 09:21 — forked from marschhuynh/reset-commit-author.md
reset-commit-author
git filter-branch --force --commit-filter '
          if [ "$GIT_COMMITTER_EMAIL" = "wrong@email.com" ];
          then
                  export GIT_COMMITTER_NAME="New Name";
                  export GIT_AUTHOR_NAME="New Nam";
                  export GIT_COMMITTER_EMAIL="new@example.com";
                  export GIT_AUTHOR_EMAIL="new@example.com";
          fi;
 git commit-tree "$@"
//Give level and quantity of dragon you want to merge
//Calculate number of level 1 dragon you need to reach it.
//Knowning merging 3 lower level dragons will get 1 dragon which has higher 1 level.
//Merging 5 lower level will get 2 dragons which have higher 1 level.
function numOfDragon(level, quantity) {
if(level == 0) return 0;
else if(level == 1) return 1 * quantity;
if(quantity % 2 == 0) {
return numOfDragon(level - 1, quantity / 2 * 5);
}
@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