Export all collection documents in
#mongodb #export #mongoexport #mongodump #collection #database
MongoDB
to a JSON
file:mongoexport --db YOUR_DATABASE --collection YOUR_COLLECTION_NAME --out YOUR_OUTPUT_FILE_NAME.json
NOTE:
do not use this command for full database backup! Use mongodump
instead#mongodb #export #mongoexport #mongodump #collection #database
Install
Prepare for compilation:
By default, htop will be installed under
build and install
Voila! You're done. just run it using:
#linux #centos #htop #compile #source #install
htop
on CentOS
from source:htop
is a real-time process viewer for Linux. First, install prerequisites and download the source:yum groupinstall "Development Tools"
yum install ncurses-devel
wget http://hisham.hm/htop/releases/2.0.2/htop-2.0.2.tar.gz
tar xvfvz htop-2.0.2.tar.gz
cd htop-2.0.2/
Prepare for compilation:
./configure
By default, htop will be installed under
/usr/local/bin
. If you want to change installation location to something else (e.g., /usr/ bin`), run configure script with `--prefix
option instead. For example:./configure --prefix=/usr
build and install
htop
as follows:make
make install
Voila! You're done. just run it using:
htop
#linux #centos #htop #compile #source #install
https://auth0.com/blog/secure-your-react-and-redux-app-with-jwt-authentication/
#react #redux #js #jwt #authentication #auth0
#react #redux #js #jwt #authentication #auth0
Auth0 - Blog
Secure Your React and Redux App with JWT Authentication
Learn how to add JWT authentication to your React and Redux app. Use Redux middleware to make secure calls to an API.
For
It has been said in API documentation that send data like below:
There is an online tool for exactly that specific purpose (encode, decode base64).
Go to link below:
- https://www.base64encode.org/
#base64 #base64encode #client_id #client_secret #api #rest #webservice
REST APIs
it usually happens to encode client-id and client-secret to send to an endpoint to get access token.It has been said in API documentation that send data like below:
Basic BASE64_ENCODEDED_VALUE_OF(CLIENT_ID:CLIENT_SECRET)
There is an online tool for exactly that specific purpose (encode, decode base64).
Go to link below:
- https://www.base64encode.org/
#base64 #base64encode #client_id #client_secret #api #rest #webservice
Base64 Encode
Base64 Encode and Decode - Online
Encode to Base64 format or decode from it with various advanced options. Our site has an easy to use online tool to convert your data.
You are on a server and all of a sudden you need your public
The website will just spit out the IP address with no bullshit around it! It is more specifically used by
#linux #sysadmin #curl #ifconfig #ifconfigco
IP address
. You can do it using cURL
and terminal:$ curl ifconfig.co
142.17.150.17
The website will just spit out the IP address with no bullshit around it! It is more specifically used by
sysadmins
.#linux #sysadmin #curl #ifconfig #ifconfigco
In order to load
This will keep the default config_files list intact, but use .json instead of .conf for the files it looks for.
#python #cement #json #config
json
config file in Cement
python framework, you simply need to include the json extension, and then set the CementApp.Meta.config_handler
to json
:from cement.core.foundation import CementApp
class MyApp(CementApp):
class Meta:
label = 'myapp'
extensions = ['json']
config_handler = 'json'
config_extension = '.json'
This will keep the default config_files list intact, but use .json instead of .conf for the files it looks for.
#python #cement #json #config
In case you want to store special characters inside of
#database #mysql #charset #character_set #collate #utf8 #utf8_unicode_ci #alter
MySQL
table field, you need to change the table encoding like below:ALTER TABLE YOUR_TABLE CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
#database #mysql #charset #character_set #collate #utf8 #utf8_unicode_ci #alter
Simplify chained comparison
It sometimes happen you write code in python like below:
if your_date >= start_date and your_date <= end_date:
pass
You can simplify the code above as below:
if start_date <= issue_date <= end_date:
pass
This kind of comparison is called
chained comparison
in a simplified manner.#python #if #chained_comparison
How to get method name in python?
The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For example, it can help you examine the contents of a class, retrieve the source code of a method, extract and format the argument list for a function, or get all the information you need to display a detailed traceback.
You can use
A sample code for the
The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For example, it can help you examine the contents of a class, retrieve the source code of a method, extract and format the argument list for a function, or get all the information you need to display a detailed traceback.
You can use
inspect
module to do exactly this job:curframe = inspect.currentframe()The part that you are interested in, is
calframe = inspect.getouterframes(curframe, 2)
caller_method = calframe[0][3]
calframe[0][3]
. It returns function name of the current method. If this method is called from a parent method (caller method), you have to get that method name using calframe[1][3]
.A sample code for the
inspect
module:import inspect#python #inspect #calframe #method_name
class PDFtoJPG:
def _internal_conversion(self):
self.convert_to_jpg()
def convert_to_jpg(self):
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
print calframe[0][3]
print calframe[1][3]
print calframe[2][3]
def convert(self):
self._internal_conversion()
snd = PDFtoJPG()
snd.convert()
Tech C**P
How to get method name in python? The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For example, it can help you examine…
You can also use
#python #inspect #stack
inspect.stack()[2][3]
instead of getting current frame and then getting its outer frames:inspect.stack
returns a list of frame records for the caller’s stack. The first entry in the returned list represents the caller; the last entry represents the outermost call on the stack.#python #inspect #stack
How to work with
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time.
Now you want to switch branches, but you don’t want to commit what you’ve been working on yet, to stash your modified files in your project use
Now your working directory should be clean:
To list all your stashes use
Now if you want to apply the most recent stashed files:
In order to remove a
These are some general, most useful commands to work with
#git #stash #stash_apply #stash_list #stash_drop #stash_save
stash
in git
?Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time.
Now you want to switch branches, but you don’t want to commit what you’ve been working on yet, to stash your modified files in your project use
git stash
:$ git stash
Saved working directory and index state \
"WIP on master: 049d078 added the index file"
HEAD is now at 049d078 added the index file
(To restore them type "git stash apply")
Now your working directory should be clean:
$ git status
# On branch master
nothing to commit, working directory clean
To list all your stashes use
git stash list
:$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
Now if you want to apply the most recent stashed files:
$ git stash apply
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: index.html
# modified: lib/simplegit.rb
In order to remove a
stash
, use git stash drop YOUR_STASH
:$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
$ git stash drop stash@{0}
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
These are some general, most useful commands to work with
stash
. Enjoy the article :)#git #stash #stash_apply #stash_list #stash_drop #stash_save
Commit
part of a file in git
:You can use
git add --patch <filename>
(or -p
for short), and git will begin to break down your file into what it thinks are sensible hunks
(portions of the file). It will then prompt you with this question:Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?
Here is a description of each option:
y
stage this hunk for the next commitn
do not stage this hunk for the next commitq
quit; do not stage this hunk or any of the remaining hunksa
stage this hunk and all later hunks in the filed
do not stage this hunk or any of the later hunks in the fileg
select a hunk to go to/
search for a hunk matching the given regexj
leave this hunk undecided, see next undecided hunkJ
leave this hunk undecided, see next hunkk
leave this hunk undecided, see previous undecided hunkK
leave this hunk undecided, see previous hunks
split the current hunk into smaller hunkse
manually edit the current hunk#git #patch #commit #hunk #stage #git_add #git_add_patch