React Js Tutorial: How to use Github pages root as your personal homepage using gh-pages
GitHub pages is a great place to host your website and lot’s of people use it to host one page apps, you just need to edit, push and changes are live.
While I was working on one of my projects, more specifically my personal homepage built with React, I’ve stumbled upon a problem related with the package gh-pages, used to easily push the code to GH. The issue is that gh-pages by default uses the branch ‘gh-pages’ inside GitHub and if you want to host it on the root of your GitHub personal page, you need to use a branch called ‘master’.
So here’s an example (code partially from the great freecodecamp article on medium):
You create a repository with your username, in my case:
Following freecodecamp’s article, you then need to setup npm to do the deploy using gh-pages, after that, you can easily push the code to GitHub using:
[html]npm run deploy[/html]
This runs the pre-defined command:
[html]npm run build&amp;&amp;gh-pages -d build[/html]
The solution is to edit the command to:
[html]npm run build&amp;&amp;gh-pages -b master -d build[/html]
This will force gh-pages to push the code to the master branch, making it possible to be used on the root of your GitHub page.
Yii2 Insert and Ignore duplicates
One of the things that comes with learning a framework is that we should change a bit the way we work in order to correctly build an app.
One of the frameworks I’ve used the most (on a personal and professional level) is Yii2 and my experience has been excellent – fast, reliable and well maintained.
One of the pain points I got since the beginning is the way the database interaction system works that in the end is quite simple, but only now that I understand it. One of the situations that I had to solve was how to do an Insert/Update, so below here’s a snippet on how to do it.
$model::YourModel::findOne(ID); // findOne() searches for the table key, you can use find()->where(‘=’, ‘column’, ‘name’)->one(); to identify the model.
$model = new YourModel;
$model->column_1 = ‘text’;
$model->column_2 = 123;
The logic is:
- You try to find if you already have the item in the Databse by calling the findOne(key);
- If there’s no model, create it from scratch;
- Assign values to the fields
That should really be it, I’m surprised there’s no other documentation explaining this quickly and simple.
Feel free to post any questions below.