Git Product home page Git Product logo

blog's People

Contributors

thanh-vinh avatar

Watchers

 avatar  avatar

blog's Issues

Header

title

Connecting people

body

Beautifully crafted with the latest technologies, SASS & Bootstrap 4.1.3, Mundana is the perfect design for your professional blog. Homepage, post article and category layouts available.

buttonText

About us

image

Vim for beginners

Introduction

Following this to practice Vim.

Install Neovim

You can install Neovim from download, package, or source in just a few seconds.

Plugins

Install vim-plug

Unix

curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Windows

curl -fLo vimfiles\autoload\plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

FAQ

How to find the location of vim configuration file

Enter command :version in Vim to see system vimrc file.

image

Enter :echo $VIM to see $VIM location.

image

References

Setup a proxy on Linux

Photo by Petter Lagson | Unsplash

Install squid

sudo apt update
sudo apt install squid3
sudo apt install apache2-utils

Setup the password store

sudo htpasswd -c /etc/squid/passwords <user-name>

You will be prompted for entering the password. Enter and confirm it.

Config squid proxy

Backup the default config file

sudo mv /etc/squid/squid.conf /etc/squid/squid.conf.backup

Make a new config file

sudo nano /etc/squid/squid.conf

Enter this in the config file

auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 24 hours
auth_param basic casesensitive off
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all
dns_v4_first on
forwarded_for delete
via off
http_port 3128
  • auth_param basic credentialsttl 24 hours: after 24 hours, user/pass will be asked - again.
  • auth_param basic casesensitive off: case sensitive for user is off.
  • dns_v4_first on: use only IPv4 to speed up the proxy.
  • forwarded_for delete: remove the forwarded_for http header which would expose your source to the destination
  • via off: remove more headers to avoid exposing the source.
  • http_port 8888: port 3128 is used for proxy. You can choose any port.

Restart the squid service

sudo service squid restart

To check the status

sudo service squid status

Setup that proxy in your compute

Please use these for manual proxy setup

  • Address: your server ip or domain name
  • Port: 3128

Reference

squid_proxy_tutorial.md

Build and release the Android app

Photo by Rami Al-zayat | Unsplash

Signing the app

Create a keystore

To publish on the Play Store, you need to give your app a digital signature. Use the following instructions to sign your app.

keytool -genkey -v -keystore key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias <alias-name>

Enter keystore password: <a-generated-pwd>
Re-enter new password: <a-generated-pwd>
What is your first and last name?
  [Unknown]:  Freemind
What is the name of your organizational unit?
  [Unknown]:
What is the name of your organization?
  [Unknown]:  Freemind
What is the name of your City or Locality?
  [Unknown]:
What is the name of your State or Province?
  [Unknown]:
What is the two-letter country code for this unit?
  [Unknown]:  VN
Is CN=Freemind, OU=Unknown, O=Freemind, L=Unknown, ST=Unknown, C=VN correct?
  [no]:  yes

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
        for: CN=Freemind, OU=Unknown, O=Freemind, L=Unknown, ST=Unknown, C=VN
Enter key password for <hidden-alias-name>
        (RETURN if same as keystore password):
[Storing key.jks]

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore key.jks -destkeystore key.jks -deststoretype pkcs12".

Put key.jks into <app dir>/android/

Reference the keystore from the app

Create a file named <app dir>/android/key.properties that contains a reference to your keystore:

storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=../key.jks

Configure signing in gradle

Add code before android block

/// Signing
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

Sign the app with signing configuration info

/// Signing
signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}

Use that siging key for both debug and release

buildTypes {
    debug {
        signingConfig signingConfigs.release
    }

    release {
        signingConfig signingConfigs.release
    }
}

Fingerprints

keytool.exe -list -v -keystore key.jks -alias <alias-name> -storepass <your-store-pwd> -keypass <your-key-pwd>

Alias name: <alias-name>
Creation date: May 13, 2020
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Freemind, OU=Unknown, O=Freemind, L=Unknown, ST=Unknown, C=VN
Issuer: CN=Freemind, OU=Unknown, O=Freemind, L=Unknown, ST=Unknown, C=VN
Serial number: 11637590
Valid from: Wed May 13 09:26:35 ICT 2020 until: Sun Sep 29 09:26:35 ICT 2047
Certificate fingerprints:
         MD5:  ...
         SHA1: ...
         SHA256: ...
Signature algorithm name: SHA256withRSA

Firebase doesn't work if you don't provide SHA-1 in the Firebase console.

Build / test / optimization

TBD

References

https://flutter.dev/docs/deployment/android

Null-aware Operators in Dart

This is an updated version of Jonathan White’s blog post about Null-aware operators in Dart. Most of the content is unchanged with the exception of the examples provided at the end of the post, which help make the post easier to understand.

Null-aware operators in dart allow you to make computations based on whether or not a value is null. It’s shorthand for longer expressions.

Photo by Max Chen | Unsplash

??

Use ?? when you want to evaluate and return an expression IFF another expression resolves to null.

exp ?? otherExp

is similar to

((x) => x == null ? otherExp : x)(exp)

??=

Use ??= when you want to assign a value to an object IFF that object is null. Otherwise, return the object.

obj ??= value

is similar to

((x) => x == null ? obj = value : x)(obj)

?.

Use ?. when you want to call a method/getter on an object IFF that object is not null (otherwise, return null).

obj?.method()

is similar to

((x) => x == null ? null : x.method())(obj)

You can chain ?. calls, for example:

obj?.child?.child?.getter

If obj, or child1, or child2 are null, the entire expression returns null. Otherwise, getter is called and returned.

?…

Dart 2.3 brings in a spread operator (…) and with it comes a new null aware operator, ?... !

Placing ... before an expression inside a collection literal unpacks the result of the expression and inserts its elements directly inside the new collection.

So now, these two are equivalent.

List numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

and

List lowerNumbers = [1, 2, 3, 4, 5];
List upperNumbers = [6, 7, 8, 9, 10];
List numbers = […lowerNumbers…upperNumbers];

To benefit from the new null aware operator, you can use it like this.

List lowerNumbers = [1, 2, 3, 4, 5];
List upperNumbers = [6, 7, 8, 9, 10];
List numbers = […lowerNumbers?…upperNumbers];

which is the equivalent to

List numbers = [];
numbers.addAll(lowerNumbers);

if(upperNumbers != null) {
    numbers.addAll(upperNumbers);
}

Singleton in Dart

Photo by Chris Ried | Unsplash

Private constructor

class Example {
    static final instance = Example._();

    Example._() {
        // Private constructor
    }

    void hello() {
        print('Hello world');
    }
}

// Call `hello` method
Example.instance.hello();

Factory

class Example {
    factory Example() => _instance;

    static final _instance = Example._internal();

    <!-- // Example._internal(); -->

    void hello() {
        print('Hello world');
    }
}

// Call `hello` method
Example().hello();

Footer

copyright

Copyright © Ez-Connect 2020 . All rights reserved.

license

Made with Mundana Theme by WowThemes.net

Measure elapsed time

image

These're some ways you can use to measure execution time of a piece of your code.

Stopwatch

Stopwatch stopwatch = new Stopwatch()..start();
doSomething();
print(stopwatch.elapsed);

Devtools

To perform custom performance traces programmatically and measure wall/CPU time of arbitrary segments of Dart code similar to what would be done on Android with systrace, use dart:developer Timeline utilities to wrap the code you want to measure such as

import 'dart:developer';

Timeline.startSync('interesting function');
doSomething();
Timeline.finishSync();

Then open your app’s Observatory’s timeline page, check the ‘Dart’ recording option and perform the function you want to measure.

See more in Tracing Dart code performance

Windows Subsystem for Linux Installation Guide for Windows 10

Install the Windows Subsystem for Linux

Before installing any Linux distros for WSL, you must ensure that the "Windows Subsystem for Linux" optional feature is enabled:

  1. Open PowerShell as Administrator and run:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  1. Restart your computer when prompted.

Install your Linux Distribution of Choice

You can install your preferred distro(s) using PowerShell 1 or Curl

Invoke-WebRequest -Uri https://aka.ms/wsl-debian-gnulinux -OutFile Debian.appx -UseBasicParsing
curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-debian-gnulinux

WSL 2

WSL 2 is a new version of the architecture in WSL that changes how Linux distros interact with Windows. WSL 2 has the primary goals of increasing file system performance and adding full system call compatibility. Each Linux distro can run as a WSL 1, or a WSL 2 distro and can be switched between at any time. WSL 2 is a major overhaul of the underlying architecture and uses virtualization technology and a Linux kernel to enable its new features. 2

Installation Instructions for WSL 2

Enable the 'Virtual Machine Platform' optional component and make sure WSL is enabled

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Set a distro to be backed by WSL 2 and make WSL 2 your default architecture using the command line

wsl --set-version Debian 2
wsl --set-default-version 2

To verify what versions of WSL each distro is using use the following command (only available in Windows Build 18917 or higher):

wsl -l -v

  NAME      STATE           VERSION
* Debian    Stopped         2

User Experience 3

  • Place files that your Linux apps will access in your Linux root file system for faster file performance speed
  • In initial builds of the WSL 2 preview you will need to access network applications using an IP address and not using localhost
  • WSL 2 uses a Virtual Hardware Disk (VHD) to store your files and if you reach its max size you may need to expand it
  • When starting, WSL 2 will now use a small proportion of memory
  • Cross OS file access speed will be slower in initial preview builds

WSL 2 FAQ

https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq

Notes

How to reboot wsl:

WIN+R -> services.msc
Find LxssManager
Right-click -> Restart

Or PowerShell command:

Get-Service LxssManager | Restart-Service

Or

debian --shutdown

Use root user as default:

debian config --default-user root

Troubleshoot problems

No network 4

Only change nameserver in /etc/resolv.conf will works on some cases.

On WSL

###
# Fix net work issues
###

# Switch to root
sudo su

# Delete auto-generated files
rm /etc/resolv.conf
rm /etc/wsl.conf

# Enable changing /etc/resolv.conf
# Enable extended attributes on Windows drives
cat <<EOF > /etc/wsl.conf
[network]
generateResolvConf = false

[automount]
enabled = true
options = "metadata"
mountFsTab = false
EOF

# Use cloudflare for DNS resolution
cat <<EOF > /etc/resolv.conf
nameserver 1.1.1.1
EOF

Exit WSL then on Windows Terminal as Admin

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Footnotes

  1. Download using PowerShell

  2. About WSL 2

  3. User Experience Changes Between WSL 1 and WSL 2

  4. No network connection in any distribution under WSL 2

Adding a splash screen to your Flutter app

Photo by CoinView App | Unsplash

iOS launch screen

Override LaunchImage*.png in ios/Runner/Assets.xcassets/LaunchImage.imageset with your assets.

Android launch screen

In Android, there are two separate screens that you can control:

  • a launch screen shown while your Android app initializes
  • and a splash screen that displays while the Flutter experience initializes.

They are defined in styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Theme applied to the Android Window while the process is starting -->
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
    <!-- Theme applied to the Android Window as soon as the process has started.
         This theme determines the color of the Android Window while your
         Flutter UI initializes, as well as behind your Flutter UI while its
         running.
         
         This Theme is only used starting with V2 of Flutter's Android embedding. -->
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@android:color/white</item>
    </style>
</resources>

We will use the same assets for both launch screen and splash screen.

...
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>

Then upgrade launch_background.xml with a specific bitmap.

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/launch_screen" />
    </item>
</layer-list>

launch_sreen.png must be copied to android/app/src/main/res/drawable-xxxhdpi/ before use.

References

Tags

Description

Describe all available tags

DNS Configuration

DNS

We use Cloudflare nameservers to serve.

Type Value
NS iris.ns.cloudflare.com
NS phil.ns.cloudflare.com

On namecheap for example

Subdomain

Configure a subdomain, example docs.freemind.vn.

Surge

Setup DNS records for Surge

Type Name Content
CNAME docs na-west1.surge.sh
A 1 docs 45.55.110.124

Deloy to the custom domain param

$ surge path/to/my-project docs.freemind.vn

?> You can save your custom domain so you don’t have to type it in each time you deploy. Simply add a CNAME file (no extension) to the root of the project you’re deploying, and Surge will use that automatically.

$ echo docs.freemind.vn > CNAME

ZEIT

Setup DNS records for ZEIT

Type Name Content
CNAME docs alias.zeit.co

If your DNS hosted with Cloudflare, try to disable Proxied -> DNS Only to verify.

Netlify

Setup DNS records for Netlify

Type Name Content
CNAME docs site-name.netlify.com2

GitLab pages

Setup DNS records for Pages

Type Name Content
CNAME 3 docs freemind.gitlab.io
A 1 docs 35.185.44.232

It may take up to 30 minutes before the site is available after the first deployment


Navigate New Pages Domain, add the docs.freemind.vn subdomain.

Footnotes

  1. If your DNS provider doesn’t support CNAME records for apex domains, you can set an A record 2

  2. Your site name in Netlify

  3. Your namespace url

Syncing a fork

Sync a fork of a repository to keep it up-to-date with the upstream repository.

Before you can sync your fork with an upstream repository, you must configure a remote that points to the upstream repository in Git.

Photo by Medium

List the current configured remote repository for your fork

git remote -v

origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

Specify a new remote upstream repository that will be synced with the fork

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

Verify the new upstream repository you've specified for your fork

git remote -v

origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

Syncing

Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master.

git fetch upstream

Check out your fork's local master branch

git checkout master

Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes.

git merge upstream/master

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.