Skip to content

Instantly share code, notes, and snippets.

@csyhuang
Last active October 24, 2018 14:57
Show Gist options
  • Save csyhuang/7af16f98a2bad9ca62d04e66c5913b4f to your computer and use it in GitHub Desktop.
Save csyhuang/7af16f98a2bad9ca62d04e66c5913b4f to your computer and use it in GitHub Desktop.

Revisions

  1. csyhuang revised this gist Oct 24, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -88,4 +88,8 @@ and then run by
    ```
    $ py.test tests/script.py::particular_module --profile
    ```

    ### Create Symlink in Linux
    On terminal
    ```
    ln -s /folderorfile/link/will/point/to /name/of/the/link
    ```
  2. csyhuang revised this gist Oct 2, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@
    ### Profiling of unittests
    ```
    $ python -m cProfile -o profile $(which py.test)
    $ python -m cProfile -o profile $(which py.test) tests/script.py::particular_module
    ```
    Afterwards, in python
    ```python
  3. csyhuang revised this gist Oct 2, 2018. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -78,6 +78,11 @@ for i in range(len(chunk_description)):
    .format(time_array[i+1]-time_array[i]))
    ```
    ### Use `pytest-profile` to profile a single test
    Install via
    ```
    $ pip install pytest-profiling
    ```
    and then run by
    ```
    $ py.test tests/script.py::particular_module --profile
    ```
  4. csyhuang revised this gist Oct 2, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -77,5 +77,8 @@ for i in range(len(chunk_description)):
    logging.warning('Time needed: {}'
    .format(time_array[i+1]-time_array[i]))
    ```

    ### Use `pytest-profile` to profile a single test
    ```
    $ py.test tests/script.py::particular_module --profile
    ```

  5. csyhuang revised this gist Oct 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -60,7 +60,7 @@ $ git reset --soft HEAD~1
    ```

    ### Timing parts of a program
    ```{.python}
    ```python
    import logging
    import time

  6. csyhuang revised this gist Oct 2, 2018. 1 changed file with 22 additions and 1 deletion.
    23 changes: 22 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -57,4 +57,25 @@ Reference from [a post on StackOverflow](https://stackoverflow.com/questions/314
    ### Undo the last commit (while keeping the changes with `--soft`)
    ```
    $ git reset --soft HEAD~1
    ```
    ```

    ### Timing parts of a program
    ```{.python}
    import logging
    import time
    time_array,chunk_description = list(), list()
    time_array.append(time.time())
    ...
    time_array.append(time.time())
    chunk_description.append('DimMpMkUser')
    ...
    for i in range(len(chunk_description)):
    if time_array[i+1]-time_array[i]>1.0:
    logging.warning(chunk_description[i])
    logging.warning('Time needed: {}'
    .format(time_array[i+1]-time_array[i]))
    ```


  7. csyhuang revised this gist Oct 2, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,10 @@ with open('readable_format.txt', 'w') as stream:
    stats.print_stats()
    ```

    ### Test only a particular module (with printouts)
    ```
    pytest --capture=sys script.py::particular_module
    ```
    Reference from [a post on stackOverflow](https://stackoverflow.com/questions/13532531/python-stats-how-do-i-write-it-to-a-human-readable-file)

    ### Pull changes from another branch and sync with my own
  8. csyhuang revised this gist Oct 1, 2018. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -47,4 +47,10 @@ Optionally push your rebased branch
    git push origin v1_adminui
    ```

    Reference from [a post on StackOverflow](https://stackoverflow.com/questions/31471790/bitbucket-syncing-branch-with-another-branch?lq=1)
    Reference from [a post on StackOverflow](https://stackoverflow.com/questions/31471790/bitbucket-syncing-branch-with-another-branch?lq=1)


    ### Undo the last commit (while keeping the changes with `--soft`)
    ```
    $ git reset --soft HEAD~1
    ```
  9. csyhuang revised this gist Oct 1, 2018. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    #### Kill all background jobs
    ### Kill all background jobs
    `kill $(jobs -p)`

    #### Run unit-testing and time all procedures
    ### Run unit-testing and time all procedures
    `pytest --durations=0`

    #### Profiling of unittests
    ### Profiling of unittests
    ```
    $ python -m cProfile -o profile $(which py.test)
    ```
    @@ -20,7 +20,7 @@ with open('readable_format.txt', 'w') as stream:

    Reference from [a post on stackOverflow](https://stackoverflow.com/questions/13532531/python-stats-how-do-i-write-it-to-a-human-readable-file)

    #### To pull changes from another branch and sync with my own
    ### Pull changes from another branch and sync with my own

    Get the base branch:
    ```
  10. csyhuang revised this gist Oct 1, 2018. 1 changed file with 30 additions and 1 deletion.
    31 changes: 30 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,33 @@ with open('readable_format.txt', 'w') as stream:
    stats.print_stats()
    ```

    Reference from [a post on stackOverflow](https://stackoverflow.com/questions/13532531/python-stats-how-do-i-write-it-to-a-human-readable-file)
    Reference from [a post on stackOverflow](https://stackoverflow.com/questions/13532531/python-stats-how-do-i-write-it-to-a-human-readable-file)

    #### To pull changes from another branch and sync with my own

    Get the base branch:
    ```
    $ git checkout v1
    ```

    Pull in any changes to make sure you have the latest version
    ```
    git pull
    ```

    Check out your branch
    ```
    git checkout v1_adminui
    ```

    Rebase your changes on top of the v1 changes
    ```
    git rebase v1
    ```

    Optionally push your rebased branch
    ```
    git push origin v1_adminui
    ```

    Reference from [a post on StackOverflow](https://stackoverflow.com/questions/31471790/bitbucket-syncing-branch-with-another-branch?lq=1)
  11. csyhuang revised this gist Sep 28, 2018. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -12,10 +12,6 @@ Afterwards, in python
    ```python
    import pstats
    import sys
    #p = pstats.Stats('profile')
    #p.strip_dirs()
    #p.sort_stats('tottime')
    #p.print_stats()

    with open('readable_format.txt', 'w') as stream:
    stats = pstats.Stats('profile', stream=stream)
  12. csyhuang revised this gist Sep 28, 2018. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,14 @@ Afterwards, in python
    ```python
    import pstats
    import sys
    p = pstats.Stats('profile')
    p.strip_dirs()
    p.sort_stats('tottime')
    p.print_stats()
    ```
    #p = pstats.Stats('profile')
    #p.strip_dirs()
    #p.sort_stats('tottime')
    #p.print_stats()

    with open('readable_format.txt', 'w') as stream:
    stats = pstats.Stats('profile', stream=stream)
    stats.print_stats()
    ```

    Reference from [a post on stackOverflow](https://stackoverflow.com/questions/13532531/python-stats-how-do-i-write-it-to-a-human-readable-file)
  13. csyhuang revised this gist Sep 28, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,9 @@ $ python -m cProfile -o profile $(which py.test)
    Afterwards, in python
    ```python
    import pstats
    import sys
    p = pstats.Stats('profile')
    p.strip_dirs()
    p.sort_stats('tottime')
    p.print_stats(50)
    p.print_stats()
    ```
  14. csyhuang revised this gist Sep 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    $ python -m cProfile -o profile $(which py.test)
    ```
    Afterwards, in python
    ```{python}
    ```python
    import pstats
    p = pstats.Stats('profile')
    p.strip_dirs()
  15. csyhuang revised this gist Sep 28, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,12 @@
    #### Profiling of unittests
    ```
    $ python -m cProfile -o profile $(which py.test)
    ```
    Afterwards, in python
    ```{python}
    import pstats
    p = pstats.Stats('profile')
    p.strip_dirs()
    p.sort_stats('tottime')
    p.print_stats(50)
    ```
  16. csyhuang revised this gist Sep 28, 2018. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,9 @@
    `kill $(jobs -p)`

    #### Run unit-testing and time all procedures
    `pytest --durations=0`
    `pytest --durations=0`

    #### Profiling of unittests
    ```
    $ python -m cProfile -o profile $(which py.test)
    ```
  17. csyhuang revised this gist Sep 27, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,5 @@
    #### Kill all background jobs
    `kill $(jobs -p)`
    `kill $(jobs -p)`

    #### Run unit-testing and time all procedures
    `pytest --durations=0`
  18. csyhuang revised this gist Sep 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    # Kill all background jobs
    #### Kill all background jobs
    `kill $(jobs -p)`
  19. csyhuang created this gist Sep 25, 2018.
    2 changes: 2 additions & 0 deletions Basic-Bash-Command.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # Kill all background jobs
    `kill $(jobs -p)`