Posts

Showing posts from 2018

Git: Thay Đổi Commit Cuối Cùng (commit amend)

Nếu như bạn thực hiện xong commit và rồi sau đó mới nhận ra rằng đã quên tổ chức các thay đổi trong tập tin bạn muốn để thêm vào commit đó, bạn có thể chạy lệnh sau: $ git add forgotten_file $ git commit --amend $ git push --force

Delete the second last commit

Delete the second last commit Let's say the bad commit  dd61ab32  is not the top commit, but a slightly older one, e.g. the second last one. We want to remove it, but keep all commits that followed it. In other words, we want to rewrite the history and force the result back to  mathnet/master . The easiest way to rewrite history is to do an interactive rebase down to the parent of the offending commit: 1: $ git rebase -i dd61ab32^ This will open an editor and show a list of all commits since the commit we want to get rid of: 1: 2: 3: pick dd61ab32 pick dsadhj278 .. . Simply remove the line with the offending commit, likely that will be the first line (vi: delete current line =  dd ). Save and close the editor (vi: press  :wq  and return). Resolve any conflicts if there are any, and your local branch should be fixed. Force it to the remote and you're done: 1: $ git push mathnet -f

Git Rebase

Image
Referal link:  https://git-scm.com/book/vi/v1/Ph%C3%A2n-Nh%C3%A1nh-Trong-Git-Rebasing - Firstly: - Merge: - Rebase: - Step 1: $ git checkout experiment $ git rebase master First, rewinding head to replay your work on top of it... Applying: added staged command - Step 2: Đến lúc này, bạn có thể quay lại nhánh  master  và thực hiện fast-forward merge $ git checkout master $ git merge experiment **Note** - rebase vo "nhanh chinh". - merge tu "nhanh phu"

Understand promises before you start using async/await

Referal link:  https://medium.com/@bluepnume/learn-about-promises-before-you-start-using-async-await-eb148164a9c8 Understand promises before you start using async/await With Babel now supporting async/await out of the box, and ES2016 (or ES7) just around the corner, more and more people are realizing how awesome this pattern is for writing asynchronous code, using synchronous code structure. This is a good thing™, and ought to improve code quality a whole lot. However, what a lot of people may have missed is that the entire foundation for async/await is promises . In fact every async function you write will return a promise, and every single thing you await will ordinarily be a promise. Why am I emphasizing this? Because so much javascript written today is written using the callback pattern, a lot of people just never got on the promise bandwagon, and they’re missing an important part of the async/await puzzle. What even is a promise? I’ll keep this b...

Beginner’s guide to Webpack

Image
Beginner’s guide to Webpack Referal Link:  https://medium.com/javascript-training/beginner-s-guide-to-webpack-b1f1a3638460 Or what I wish I knew when starting with Wepback. Click here to go to the final Github repo. We are using Webpack 1.x. Webpack 2 will not work with this tutorial. Click here to view the Webpack changelog. Webpack is the latest and greatest in front-end development tools. It is a module bundler that works great with the most modern of front-end workflows including Babel, ReactJS, CommonJS, among others. As a beginner to Webpack, this is what I have learned. This tutorial has been updated to use Babel 6 Getting Started Webpack Conventions Webpack works best with NPM, not Bower Uses a module system (AMD, CommonJS, ES6) Installing Webpack globally: npm install webpack -g The most basic of builds: In your root directory create 2 files: index.html & app.js In app.js: document.write('welcome to my app'); console.log('...

When to use Component or PureComponent

Reference:  https://codeburst.io/when-to-use-component-or-purecomponent-a60cfad01a81 When to use Component or PureComponent I switched to using PureComponent awhile back on the premise of it being a more performant version of Component. This turned out to be true, but the performance gains come with a few strings attached. Let’s dig in to PureComponent and understand why we should be using it. Component and PureComponent have one difference PureComponent  is exactly the same as  Component  except that it handles the shouldComponentUpdate  method for you . When props or state changes,  PureComponent  will do a  shallow comparison  on both props and state.  Component  on the other hand won’t compare current props and state to next out of the box. Thus, the component will re-render by default whenever  shouldComponentUpdate  is called. Shallow Comparison 101 When comparing previous props and state to next, a shal...

Logout Git on MacOS

Image
Managing Remotes  / Updating credentials from the OSX Keychain Updating credentials from the OSX Keychain You'll need to update your saved username and password in the  git-credential-osxkeychain helper if you change your password or username on GitHub. Updating your credentials via Keychain Access In Finder, search for the  Keychain Access  app. In Keychain Access, search for  github.com . Find the "internet password" entry for  github.com Edit or delete the entry accordingly. Deleting your credentials via the command line Through the command line, you can use the credential helper directly to erase the keychain entry. To do this, type the following command: git credential-osxkeychain erase host=github.com protocol=https [Press Return] If it's successful, nothing will print out. To test that it works, try and clone a repository from GitHub. If you are prompted for a password, the keychain entry was deleted. ...