Monday, November 19, 2018

sourcetree, Error: remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/


I found the answer here, it is a known bug for version 2.1.8+
The following steps fixed it for me:
Tools > Options > Git > Update Embedded Git
Also pushing with the command line works.
EDIT
Also adding @Latisha's answer:
1. Do the above.
2. Delete AppData\Local\Atlassian\SourceTree\passwd 
3. Restart SourceTree
4. Hurray!!!

ssh login to github


The problem is, you are trying to use the public key for authentication. The private key, is e.g. id_rsa2 while the public key is id_rsa2.pub, at least per default, when generated with ssh-keygen.
As default ssh uses id_rsa for identification, so you have to use:
ssh -i ~/.ssh/id_rsa2 -T git@github.com
The ssh config should look like this:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa2
The Host value is important, because that's what you have to use to use the configuration. You now can use ssh github.com. If you don't change the Host line, you need to use ssh github, but this could break other tools.
Alternatively you could use ssh-agent. In this case you do not need to create the config and just add the key to your ssh-agent and ssh to github.
ssh-add ~/.ssh/id_rsa2
ssh -T git@github.com

Wednesday, October 10, 2018

Remove installed on Centos

If everything was installed via the yum package manager, you can undo previous commands:

# Get all yum commands previously run
yum history list all

# Get the details of the command
yum history info [entry number]

# Undo each command top-down
yum history undo [entry number]

Yii2 Sconarios 作用


二、场景


1、场景说的通俗点,就是不同条件下环境。举个用户注册的例子,普通用户在注册的时候只要用户名、密码、电子邮箱就可以了, 而企业用户除了这些外还需要提供企业名称、法人名称、营业执照号什么的,这就是两个不同的场景。 为了让一个模型能使用在不同的场景下面,Yii里面提供了scenarios()方法,返回的也是name-value数组, name为每个不同 的场景,value是一个数组,为对应场景的所用到的属性。

public function scenarios()
{
    return [
        'login' => ['username', 'password'],
        'register' => ['username', 'email', 'password'],
    ];
}
如上所示,用户模型里面有 username,password,email三个属性,在登录的场景下只需要username和password,而在注册的场景中还需要email。 如果没有在模型中定义场景scenarios(),那么将会使用默认的场景,即所有的属性都将使用。 

2、如果在定义场景的同时还要保持默认的场景可用,那么就得需要调用父类的scenarios()

public function scenarios()
{
    $scenarios = parent::scenarios();
    $scenarios['login'] = ['username', 'password'];
    $scenarios['register'] = ['username', 'email', 'password'];
    return $scenarios;
}
3、有时候我们在批量赋值的时候需要标明某些属性是不安全的,但又想让让这些属性能够正常的验证。 我们可以在场景scenarios()中的那些属性前面加上感叹号前缀,如

['username', 'password', '!secret']
username, password 和secret都能被验证,但在给属性批量赋值的时候只有username和password被认识是安全的可以赋值,而secret就不能被赋值 4、条件验证 可以在满员某些条件的情况下才验证属性,例如一个属性的验证需要另外一个属性值(确认密码等),这个时候可以用when关键字来定义

['state', 'required', 'when' => function($model) { return $model->country == Country::USA; }],
['stateOthers', 'required', 'when' => function($model) { return $model->country != Country::USA; }],
['mother', 'required', 'when' => function($model) { return $model->age < 18 && $model->married != true; }],
如果需要在客户端进行逻辑验证(enableClientValidation is true),得需要使用关键字 whenClient

['state', 'required', 'when' => $usa['server-side'], 'whenClient' => $usa['client-side']]

Friday, September 28, 2018

forgot mysql password on Centos7

What version of mySQL are you using? I''m using 5.7.10 and had the same problem with logging on as root

There is 2 issues - why can't I log in as root to start with, and why can I not use 'mysqld_safe` to start mySQL to reset the root password.

I have no answer to setting up the root password during installation, but here's what you do to reset the root password

Edit the initial root password on install can be found by running

grep 'temporary password' /var/log/mysqld.log
http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

systemd is now used to look after mySQL instead of mysqld_safe (which is why you get the -bash: mysqld_safe: command not found error - it's not installed)

The user table structure has changed.

So to reset the root password, you still start mySQL with --skip-grant-tables options and update the user table, but how you do it has changed.

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
mysql -u root

5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

*** Edit ***
As mentioned my shokulei in the comments, for 5.7.6 and later, you should use
   mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Or you'll get a warning

6. Stop mysql
systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:
systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p
Reference

As it says at http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,

Note

As of MySQL 5.7.6, for MySQL installation using an RPM distribution, server startup and shutdown is managed by systemd on several Linux platforms. On these platforms, mysqld_safe is no longer installed because it is unnecessary. For more information, see Section 2.5.10, “Managing MySQL Server with systemd”.

Which takes you to http://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html where it mentions the systemctl set-environment MYSQLD_OPTS= towards the bottom of the page.

The password reset commands are at the bottom of http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

Tuesday, July 17, 2018

echo "making symlink, enter sudo password"
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

 echo "migrate to new version"
/Applications/MAMP/Library/bin/mysql_upgrade -u root --password=root -h 127.0.0.1

Friday, May 4, 2018

es6 spead or reset ... , export default {...}

on es6 there is ... symbol,
1) it is transfer an array to and string and the string has been separated by ",";
such as:
var fruit = ["apple", "pear", "kiwifruit"];
console.log(...fruit);

that will be printed as

 apple, pear, kiwifruit;
2) if we are going to extend an array with another array we can do

var fruit =  ["apple", "pear", "kiwifruit"];
var moreFruits = ["pineapple", ...fruit];

the moreFruits is ["pineapple", "apple", "pear", "kiwifruit"];


3) unsure the number of parameters of function:
such as

function add(...vals){
  let sum=0;
  for(let i=0;i    sum+=vals[i];
  }
  return sum;
}

Wednesday, May 2, 2018

Vuejs $emit('close') and v-on

use component -> template @click="$emit('close')

on parent

explain in
https://laracasts.com/series/learn-vue-2-step-by-step/episodes/10?autoplay=true


communicate between parent and children components.

v-on: or @on:coupon_applied="onCouponApplied"
applied is event such as click, blur and so on
onCouponApplied is method or function name
onCouponApplied(dataName) {
  ....
}

this dataName is from children $emit passed dataName.

this method will create the method on the parent or root component.

on the children components
template: ''

in the children methods:
methods: {
  onCouponApplied() {
    this.$emit('coupon_applied', dataName)
  }
}

the dataName is object or array or some data want to send to parent.
$emit: the applied is parent event name. such as coupon_applied


Sunday, April 8, 2018

Laravel use different function name on model

Users and articles are one to many relationship database.

if I use owner instead on user in article model, we should add the foreign key such as:

class Article extent model
{
  public owner() {
    return $this->belongsTo('User', 'user_id');
  }
}

in the controller or view we can use
$article->owner->name;




Wednesday, April 4, 2018

laravel 5.2 import a project and QLSTATE[HY000] [2002] or SQLSTATE[42S02]


php artisan clear-compiled [PDOException]  SQLSTATE[HY000] [2002] No such file or directory  
change .env  to: 

DB_HOST=localhost
DB_DATABASE=jos_db
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

and config/database.php




'mysql' => [ 
'driver' => 
'mysql', 'host' => 
env('DB_HOST', 'localhost'), 'database' => 
env('DB_DATABASE', 'db'), 'username' => 
env('DB_USERNAME', 'root'), 'password' => 
env('DB_PASSWORD', 'root'), 'unix_socket' => 
env('DB_SOCKET', ''), 'charset' => 
'utf8', 'collation' => 
'utf8_unicode_ci', 'prefix' => 
'', 'strict' => false, 'engine' => 
'InnoDB', 'options' => env('DB_COMPRESS', false) ? [\PDO::MYSQL_ATTR_COMPRESS => true] : [],],



php artisan clear-compiled  [Illuminate\Database\QueryException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 
import exist database to mysql server

Wednesday, March 28, 2018

mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)

mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)

Solution:

open the docker-compose.yml file and then find ### MySQL Container

add
 user: "1000:50"

save and run docker-compose up mysql again.

Wednesday, March 7, 2018

how to reinstall or rebuild laradock

Let's just upgrade.
  1. Upgrade your LaraDock git pull origin master.
    (LaraDock v4 works only with Docker for Mac/Windows. If you want to keep using LaraDock toolbox (VM) use LaraDock v3).
  2. Rebuild your containers docker-compose build --no-cache (This might wipe your Data container)
  3. Try again.. best of luck :)

Monday, February 12, 2018

Sunday, February 4, 2018

phpunit No tests executed! on laravel

if run the phpunit and get the "No tests executed" we should run this ./vendor/bin/phpunit this will run from the project and not from the root system.

Thursday, February 1, 2018

laradock connect to database error #2002 - No such file or directory — The server is not responding (or the local server's socket is not correctly configured)

go to the laradock folder->.env find the line # Enter your Docker Host IP (will be appended to /etc/hosts). Default is `10.0.75.1`

DOCKER_HOST_IP=10.0.75.1

this is the mysql db_host_ip is 10.0.75.1


Thursday, January 25, 2018

different between 'register' and 'boot' on laravel serviceprovider

register: singleton (wihich means bind a class to current container or registering to service provider) a class to container or framework

boot or call it bootstrap which is running service provider (such as App::make('name')).

in the order running, run register at the first and then runs boot.


  1. register是向容器中注册东西
  2. boot用于启动相应的服务(例如事件监听等

Wednesday, January 17, 2018

folder permission details

There are three types of access restrictions:
Permission    Action      chmod option
======================================
read          (view)      r or 4
write         (edit)      w or 2
execute       (execute)   x or 1
There are also three types of user restrictions:
User    ls output
==================
owner   -rwx------
group   ----rwx---
other   -------rwx

Folder/Directory Permissions

Permission    Action                               chmod option
===============================================================
read          (view contents: i.e., ls command)      r or 4
write         (create or remove files from dir)      w or 2
execute       (cd into directory)                    x or 1

Numeric notation

Another method for representing Linux permissions is an octal notation as shown by stat -c %a. This notation consists of at least three digits. Each of the three rightmost digits represents a different component of the permissions: owner, group, and others.
Each of these digits is the sum of its component bits in the binary numeral system:
Symbolic Notation    Octal Notation    English
============================================================
----------            0000               no permissions
---x--x--x            0111               execute
--w--w--w-            0222               write
--wx-wx-wx            0333               write & execute
-r--r--r--            0444               read
-r-xr-xr-x            0555               read & execute
-rw-rw-rw-            0666               read & write
-rwxrwxrwx            0777               read. write & execute

Now, what does 755 mean?

7=rwx 5=r-x 5=r-x
This means that the directory has the default permissions -rwxr-xr-x (represented in octal notation as 0755).