Skip to content

Instantly share code, notes, and snippets.

@1isten
1isten / promise-chain-break.js
Last active June 9, 2020 19:32
the only way to early break Promise .then() chain is to make the code fall into .catch()
const myLimit = 3;
function checkLimit(data) {
if (data === myLimit) {
const err = new Error('let me exit!');
err.data = `${data} is the enough!!!`;
throw err; // or, return Promise.reject(err)
}
}
@1isten
1isten / laravel_passport_jwt.md
Last active December 31, 2019 15:25
Use Laravel Passport to create and manage JWT Tokens (Personal Access Tokens)

Setup according to the documentation

  • Keep the default migrations as token info will be stored at db
  • Personal Access Token is what we will use as JWT
  • Token lifetime can be set in AuthServiceProvider via personalAccessTokensExpireIn
  • No need to use CreateFreshApiToken middleware
  • Client should store tokens using JavaScript (e.g., localStorage, or js-cookie)
  • Client should append the 'Authorization': 'Bearer xxx' header manually

Create the token, use the createToken method

@1isten
1isten / javascript.json
Last active September 26, 2020 06:27
VS Code CSS snippets
{
"esdisable": {
"prefix": "esdis",
"body": [
"// eslint-disable-next-line "
],
"description": "eslint-disable-next-line"
}
}
@1isten
1isten / css.json
Last active April 8, 2020 14:08
VS Code CSS snippets
{
"General reset": {
"prefix": "reset",
"body": [
"html, $2body {",
" width: 100vw;",
" height: 100vh;",
" margin: 0;",
" border: 0;",
" padding: 0;",
@1isten
1isten / settings.json
Last active March 27, 2022 16:14
VS Code settings
{
"editor.tabSize": 2,
"editor.cursorStyle": "block",
"editor.cursorBlinking": "smooth",
"editor.cursorSmoothCaretAnimation": true,
"editor.bracketPairColorization.enabled": true,
"editor.detectIndentation": true,
"editor.formatOnPaste": true,
"editor.formatOnSave": false,
"explorer.compactFolders": false,
@1isten
1isten / ascii2svg2base64
Created September 25, 2019 15:36
use ascii art for markdown
brew install rust
cargo install svgbob_cli
~/.cargo/bin/svgbob -h
~/.cargo/bin/svgbob --font-family monospace ascii.txt -o ascii.svg
base64 -i ascii.svg | pbcopy
@1isten
1isten / vue naming
Last active October 25, 2020 02:25
my naming preferences
PascalCase:
- component file name (best practice)
e.g.
"Foo.vue"
"FooBar.vue"
- component name (match the file name, for default export)
e.g.
export default {
name: 'Foo',
{
"server": "0.0.0.0",
"local_address": "127.0.0.1",
"local_port": 1080,
"port_password": {
"8850": "0",
"8851": "1",
"8852": "2",
"8853": "3"
},
sudo gpt -r show disk0 ->
Mackintosh HD part is 234045360 blob => 234045360*512 = 119831224320 B = 119.83122432 GB
***
How to convert between Gigabytes and Gibibytes (GB & GiB)?
1 GB = 0.931322574615 GiB
1 GiB = 1.073741824 GB
***
Apple prefers GB while Microsoft prefers GiB, for example I want a perfact Windows partision with size of 50.00G(from the view of Windows) on my Mac: