Sing's Log

Knowledge worth sharing


  • Home

  • Tags

  • Timeline

  • Portfolio

  • Search

Measure gzip size via command line without actually compress it

Posted on 2018-09-03 | Edited on 2023-01-16 |

Measure compressed request size with curl, gzip and wc

To measure gzip sizing for a request, you don’t need to actually gzip it, just use pipe | to pipe the stream from curl to gzip to wc :

1
2
3
4
5
6
7
8
9
10
11
12
13
# before gzip
$ curl https://www.paddingleft.com | wc -c
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 57847 0 57847 0 0 99114 0 --:--:-- --:--:-- --:--:-- 99053
57847

# after gzip
$ curl https://www.paddingleft.com | gzip | wc -c
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 57848 0 57848 0 0 111k 0 --:--:-- --:--:-- --:--:-- 110k
10443

As you can see, before gzip it’s 57847 bytes, after gzip it’s 10443 bytes.

Measure file size after gzip

You could do same things to measure a file gzip sizing by gzip with -c option, so it won’t actually gzip it.

1
2
$ gzip -c foo.jpg | wc -c
53688

Awesome Vim cheat sheet

Posted on 2018-08-29 | Edited on 2023-01-16 |
  • My slides share[
  • Coding faster with Vim + IDE

Mode

  • insert
  • normal
  • visual
  • command

Insert mode

  • i
    • insert before the cursor
  • I
    • insert before the start of line
  • a
    • append after the cursor
  • A
    • append at the end of line

Normal mode

  • <ESC>

Visual mode

  • v
    • select a char
  • V
    • select a line
  • Ctrl + v
    • visual block mode

Command mode

: + <command>

1
2
3
:wq
:cq
:set rnu

Cursor movement


Char

  • h (left)
  • j (down)
  • k (up)
  • l (right)
  • Combile with number to move, 2k to jump 2 lines up
  • Relative line numbers :set rnu

Word

  • w or W
    • jump forwards to the start of a word
  • e or E
    • jump forwards to the end of a word
  • b or B
    • jump backwards to the start of a word
  • Capital case can contain punctuation

Single line

  • $ - end of line
  • ^ - start of the line after the indentation
  • 0 - move to the column 0

Text Object motion

  • {}
    • paragraphs forward/backward
  • ()
    • sentences forward/backward
  • []
    • backward/forward sections

Pair

  • %
    • go to the match bracket

Screen

  • H
    • move to top of screen
  • M
    • move to middle of screen
  • L
    • move to bottom of screen

File

  • gg
    • Start
  • G
    • end of file
  • :<absolute-line-numbers>
    • move to the absolute line

Scroll

  • zt
    • scroll current line to top
  • zb
    • scroll current line to bottom
  • zz
    • scroll current line to middle

Search


Search char in single line

  • f/F
    • find char, forward/backward
    • abcABCabc, fC to find middle C
  • t/T
    • Go to previous char before the char, forward/backward
    • foo.bar<> , move to r by t<
  • ;
    • Repeat t/T/f/F
  • ,
    • Reverse t/T/f/F

Search in file

  • /
    • Search forward
  • ?
    • Search backward
  • n and N
    • next and previous
  • *, #
    • search next/previous current word
    • The behavior is identical to /word

Edit

  • Undo/Redo
    • u / Ctrl+r

Insert

  • insert line before/after the current line
    • o, O
  • join two line (keep mode)
    • J

Copy

  • y + motion
    • combine with any motion, e.g. yt; or yw
  • yy = Y
    • yank (copy) the current line

Paste from clipboard registry

  • p

    • paste after
  • P

    • paste before

Cut and switch to insert mode

  • c + motion
    • Cut
  • C
    • Cut to end of line
  • s
    • Substitute the char under the cursor
  • S
    • Substitube the line
  • r
    • replace a char
  • R
    • Enter the insert-replace mode

Cut and keep in normal mode

  • d
    • d3j or 3dd
  • D
    • Delete to end of the line
  • dd
    • Delete the entire line
  • x and X
    • delete and backspace

inside / around

1
2
3
4
5
6
7
8
9
10
11
# edit neariest word inside symbol, e.g. }
ci}

# edit neariest word outside symbol, e.g. ]
ca]

# delete inside tag
dit

# replace word with yanked word
vi]p

Repeat action

  • repeat action
    • .

Macro

  • q + a~z
    • record macro to a~z
  • normal mode + q to quit recording
  • @ + a~z to excute macro

Bookmark

  • m + a~z
    • bookmark current location to a~z
  • ' + a~z
    • go to a~z bookmark
  • ''
    • go to the last position

Registers

  • " + a~z 0~9 "+*/:%-
    • :reg see all registers
    • " the default(unnamed) register
    • 0 the default register for y(yank)
    • +, * the system clipboard
    • / the latest search keyword
    • : the latest used command
    • % the current file path
    • # the last edited file

“adw : delete the word and save to register a

===

Registers - Advance

  • "0p - paste from last yank
  • Use the register in the Search and Command mode
    • ctrl + r + <register>

*:%s/<ctrl+r>//abc/gc to replace the lastest search keyword(*) to abc with confirmation dialog


Change multi line

  1. Ctrl + v to enter Visual block mode
  2. Move cursor to select lines that need to be edited
  3. Shift + i
  4. #
  5. Esc

More

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# increase the first right number in the line
Ctrl + A

# decrease the first right number in the line
Ctrl + X

# Make a word uppercase
gUe

# Show Line numbers
:set number

# Set relative line number
:set rnu

# get recent command list
q:

# Replace word A with word B
:%s/A/B/g

More…and more

  • ctrl+o
    • previous jump position
  • ctrl+i
    • next jump position
  • g;
    • previous Change position
  • g,
    • next Change position

vim X IDE


Setup

  • Ideavim

    1. click the V icon on the right bottom corner
    2. open ~/.ideavimrc
    3. edit and save
  • VScode


Reference

  • vim doc
  • vim register
  • vim cheatsheet

Get the difference before saving in vim

1
:w !diff % -
  • w without filename will output to stdin
  • ! will excute bash in vim
  • % is current file in vim
  • diff with - will read content from stdin

CSS padding-right disappear when position fixed width 100%

Posted on 2018-07-24 | Edited on 2023-01-16 |

When creating fixed navigation bar with padding, we got :

1
2
3
position: fixed;
width: 100%;
padding: 15px;

However you will find padding-right disappear, the reason is the width is window width + padding-left + padding-right. It is exceed the window, to fix it just use width: calc(100% - 30px) to reduce the width

1
2
3
position: fixed;
width: calc(100% - 30px);
padding: 15px;

See the Pen Fixed nav with correct padding by AsinChen (@Asing1001) on CodePen.

Line Notification with IFTTT in 5 min

Posted on 2018-06-27 | Edited on 2023-01-16 |
  1. Go to create my applet page in IFTTT
  2. Choose this > Webhooks > Receive a web request
  3. Set any event name and click create trigger
  4. Choose that > Line > Send message
  5. Set Message as value1
  6. Go to Webhooks
  7. Click Documentation on the top right corner
  8. Fill up the event name and value1 then try the curl example on the page
  9. You could see a message deliver to LINE immdiately!

Install nodejs program as windows service by nssm

Posted on 2018-05-29 | Edited on 2023-01-16 |

Steps to install windows service

  1. Create a start.bat file with content npm start
  2. Download nssm
  3. Extract it and go to nssm/win64 folder
  4. Type nssm install service-name from command prompt
  5. Select start.bat as Application Path, you could also add your startup Arguments here
  6. Start service with nssm start service-name
  7. You could find it already registered as windows service :)

NSSM commands reference

You could type nssm anytime to see this document

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
M:\nssm-2.24\win64>nssm
NSSM: The non-sucking service manager
Version 2.24 64-bit, 2014-08-31
Usage: nssm <option> [<args> ...]

To show service installation GUI:

nssm install [<servicename>]

To install a service without confirmation:

nssm install <servicename> <app> [<args> ...]

To show service editing GUI:

nssm edit <servicename>

To retrieve or edit service parameters directly:

nssm get <servicename> <parameter> [<subparameter>]

nssm set <servicename> <parameter> [<subparameter>] <value>

nssm reset <servicename> <parameter> [<subparameter>]

To show service removal GUI:

nssm remove [<servicename>]

To remove a service without confirmation:

nssm remove <servicename> confirm

To manage a service:

nssm start <servicename>

nssm stop <servicename>

nssm restart <servicename>

nssm status <servicename>

nssm rotate <servicename>

Reference

http://nssm.cc

Install Redis master-slave-sentinel on linux

Posted on 2018-05-18 | Edited on 2023-01-16 |

Before start

  1. Download and install redis from official site
  2. redis excutable commands are under bin folder, configs are under etc folder, logs are under var folder
    Read more »

Resolve concurrency limit with Bluebird-Promise.map

Posted on 2018-05-10 | Edited on 2023-01-16 |

ECONNRESET when making thousands requests

In situation doing thousands of http requests, it is easy to get error ECONNRESET, for example :

1
2
3
4
5
6
7
8
require('isomorphic-fetch');

const promises = []
for(var i=0; i<10000; i++){
promises.push(fetch('http://example.com/'+i));
}

const results = await Promise.all(promises)
Read more »

Find ports status on Windows

Posted on 2018-05-03 | Edited on 2023-01-16 |

To find ports status on windows, there is a default Windows GUI - Resource Monitor or you could use netstat via command prompt.

Read more »

Transact-SQL cheat sheet

Posted on 2018-04-25 | Edited on 2023-01-16 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Get current datetime
GETDATE()

-- Get year of datetime
YEAR(GETDATE())

-- Get difference between dates
DATEDIFF(dateformat, startdate, enddate)

-- Subtract date, e.g.: DATEADD(HOUR, -11, GETDATE())
DATEADD(Unit of time, value, date)

-- Avalable Unit of time value
NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, WEEKDAY, WEEK, DAY, DAYOFYEAR, MONTH, QUARTER, YEAR

-- Between
select * from User where CreatedDate between '2016-09-26' and '2016-09-27'

-- Order by
select * from User order by column desc

-- Group by
select UserCode, Count(*) from User group by UserCode

-- Select top 10
SELECT TOP (10) * from User

Linux Remote Desktop Viewer to Windows error connecting to host

Posted on 2018-04-14 | Edited on 2023-01-16 |

Today When I connect to Windows through Remote Desktop Viewer got error connecting to host prompt.
After searching the solution is to remove the server I’m having issue in $home/.freerdp/known_hosts and reconnecting again.

1
2
[[email protected] ~]$ vi ~/.freerdp/known_hosts
# In Vim, remove the line start with server ip you are connecting to by `dd`, and `:wq` to save the file.

Reference: https://superuser.com/questions/834447/vinagre-remote-desktop-viewer-for-gnome-isnt-working-out-of-box

1234…8
Sing Ming Chen

Sing Ming Chen

Sing's log, a developer's blog

77 posts
193 tags
GitHub E-Mail Linkedin Facebook StackOverflow
© 2023 Sing Ming Chen
Powered by Hexo v3.9.0
|
Theme — NexT.Gemini v6.3.0