MongoDB server Load Average: 0.5 (It can reach 16)
Database Size: 100GB (It is compressed in MySQL it reaches 300 GB in size!)
Req/Sec: 500
Our server seems hungry for more requests and more data.
#mongodb #mongo #awesomeness
Database Size: 100GB (It is compressed in MySQL it reaches 300 GB in size!)
Req/Sec: 500
Our server seems hungry for more requests and more data.
#mongodb #mongo #awesomeness
You are given a node that is the beginning of a linked list. This list always contains a tail and a loop.
Your objective is to determine the length of the loop.
For example in the following picture the tail's size is 3 and the loop size is 11:
Your objective is to determine the length of the loop.
For example in the following picture the tail's size is 3 and the loop size is 11:
Tech C**P
Photo
Tech C**P
# Use the `next' attribute to get the following node node.next Note: do NOT mutate the nodes! #python #codewars
Sample Tests:
# Make a short chain with a loop of 3
node1 = Node()
node2 = Node()
node3 = Node()
node4 = Node()
node1.next = node2
node2.next = node3
node3.next = node4
node4.next = node2
Test.assert_equals(loop_size(node1), 3, 'Loop size of 3 expected')
# Make a longer chain with a loop of 29
nodes = [Node() for _ in xrange(50)]
for node, next_node in zip(nodes, nodes[1:]):
node.next = next_node
nodes[49].next = nodes[21]
Test.assert_equals(loop_size(nodes[0]), 29, 'Loop size of 29 expected')
# Make a very long chain with a loop of 1087
chain = create_chain(3904, 1087)
Test.assert_equals(loop_size(chain), 1087, 'Loop size of 1087 expected')
Forwarded from Digiato | دیجیاتو
In
It will find all users that their names start with
#mongoDB #pymongo #regex
MongoDB
you can use $regex
in order to find something based on a regex pattern:my_col.find({'name': { $regex: '^ali.*' } })
It will find all users that their names start with
ali
. Now let's say you want to search users based on their phone country code which has a + in its number like +98901...
. You need to escape the + character but escape it twice:my_col.find({'phone': { $regex: '^\\+98.*' } })
#mongoDB #pymongo #regex
marshmallow
is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.- https://pypi.org/project/marshmallow/
#python #marshmallow #ORM #ODM
PyPI
marshmallow
A lightweight library for converting complex datatypes to and from native Python datatypes.
How to emulate text justification in monospace font? You will be given a single-lined text and the expected justification width. The longest word will never be greater than this width.
Here are the rules:
Use spaces to fill in the gaps between words.
Each line should contain as many words as possible.
Use '\n' to separate lines.
Gap between words can't differ by more than one space.
Lines should end with a word not a space.
'\n' is not included in the length of a line.
Large gaps go first, then smaller ones ('Lorem--ipsum--dolor--sit-amet,' (2, 2, 2, 1 spaces)).
Last line should not be justified, use only one space between words.
Last line should not contain '\n'
Strings with one word do not need gaps ('somelongword\n').
Example with width=30:
Also you can always take a look at how justification works in your text editor or directly in HTML (css: text-align: justify).
#python #codewars
Here are the rules:
Use spaces to fill in the gaps between words.
Each line should contain as many words as possible.
Use '\n' to separate lines.
Gap between words can't differ by more than one space.
Lines should end with a word not a space.
'\n' is not included in the length of a line.
Large gaps go first, then smaller ones ('Lorem--ipsum--dolor--sit-amet,' (2, 2, 2, 1 spaces)).
Last line should not be justified, use only one space between words.
Last line should not contain '\n'
Strings with one word do not need gaps ('somelongword\n').
Example with width=30:
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Vestibulum sagittis dolor
mauris, at elementum ligula
tempor eget. In quis rhoncus
nunc, at aliquet orci. Fusce
at dolor sit amet felis
suscipit tristique. Nam a
imperdiet tellus. Nulla eu
vestibulum urna. Vivamus
tincidunt suscipit enim, nec
ultrices nisi volutpat ac.
Maecenas sit amet lacinia
arcu, non dictum justo. Donec
sed quam vel risus faucibus
euismod. Suspendisse rhoncus
rhoncus felis at fermentum.
Donec lorem magna, ultricies a
nunc sit amet, blandit
fringilla nunc. In vestibulum
velit ac felis rhoncus
pellentesque. Mauris at tellus
enim. Aliquam eleifend tempus
dapibus. Pellentesque commodo,
nisi sit amet hendrerit
fringilla, ante odio porta
lacus, ut elementum justo
nulla et dolor.
Also you can always take a look at how justification works in your text editor or directly in HTML (css: text-align: justify).
#python #codewars
Tech C**P
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. - https://pypi.org/project/marshmallow/ #python #marshmallow #ORM #ODM
Object serialization deserialization ORM/ODM documentation
https://marshmallow.readthedocs.io/en/2.x-line/quickstart.html#serializing-objects-dumping
#python #marshmallow #ORM #ODM #readthedocs
https://marshmallow.readthedocs.io/en/2.x-line/quickstart.html#serializing-objects-dumping
#python #marshmallow #ORM #ODM #readthedocs
https://www.youtube.com/watch?v=XMu0T6L2KRQ&list=PLEsfXFp6DpzTOcOVdZF-th7BS_GYGguAS
#python #django #rest
#python #django #rest
YouTube
Blog API with Django Rest Framework 1 of 33 - Welcome
Blog API with Django Rest Framework 1 of 33 - Welcome
** Blog API with Django Rest Framework ** is a project to build a RESTful API service for the blog we created in Advancing the Blog and Try Django 1.9.
RESTful API services allow our applications to…
** Blog API with Django Rest Framework ** is a project to build a RESTful API service for the blog we created in Advancing the Blog and Try Django 1.9.
RESTful API services allow our applications to…
How 3rd Party Logins work like
In order to understand this concept you need to read a little bit about OAuth 2.0 flow. The flow that frontiers use in order to get access token is called
For example for
- https://accounts.google.com/o/oauth2/v2/auth?client_id=YOUR_CLIENT_ID&redirect_uri=https://example.com/callback. html&response_type=token&scope=openid+profile+email&prompt=select_account
But there are lot more going on in the background. How a modal is opened? Or when modal get the token how it sends access token to the main window (parent window)? How do you close the opened modal after successful authorization?
These are all critical questions that any frontier programmer needs to know.
One the simplest forms of opening a popup is:
We store the popup object in
- https://example.com/callback.html
Inside of that HTML you get the parameters.
Here get the hash part using
We get the hash part as
#javascript #google #3rd_party_login #login #facebook #oauth #oauth2 #implicit_flow
Facebook
, Google
, etc?In order to understand this concept you need to read a little bit about OAuth 2.0 flow. The flow that frontiers use in order to get access token is called
Implicit Flow
in this scenario in one go you get an access token and you don't need to send your client secret as everything in web is plain and end users can inspect it.For example for
Google
authentication, you use the below link with resopnse_type of token
NOT code
(code is a 2-step authentication flow):- https://accounts.google.com/o/oauth2/v2/auth?client_id=YOUR_CLIENT_ID&redirect_uri=https://example.com/callback. html&response_type=token&scope=openid+profile+email&prompt=select_account
But there are lot more going on in the background. How a modal is opened? Or when modal get the token how it sends access token to the main window (parent window)? How do you close the opened modal after successful authorization?
These are all critical questions that any frontier programmer needs to know.
One the simplest forms of opening a popup is:
window.popUpObj = window.open(url, '_blank')
We store the popup object in
window.popUpObj
in order to be able to close it in the future. As we just said in google link above we have a parameter called redirect_uri
, here you put a link to where you need to get the parameters from your 3rd party. Here we have set it to:- https://example.com/callback.html
Inside of that HTML you get the parameters.
Google
sends data in a hash section of the URL so in callback.html
we get the hash like below and then send it to the parent window using window.opener
:<script>
window.opener.loginCallback(window.location.hash);
</script>
Here get the hash part using
window.location.hash
and pass it to parent window function loginCallback
. This function is defined in your main js file like below:window.loginCallback = function(args) {
console.log('Login callback has been called, token: ', args);
window.popUpObj.close();
}
We get the hash part as
args
and then close the child window using window.popUpObj.close()
. This is the object we have recently stored to refer later.#javascript #google #3rd_party_login #login #facebook #oauth #oauth2 #implicit_flow
Tech C**P
How 3rd Party Logins work like Facebook, Google, etc? In order to understand this concept you need to read a little bit about OAuth 2.0 flow. The flow that frontiers use in order to get access token is called Implicit Flow in this scenario in one go…
A more detailed example of a sample modal is like:
#javascript #modal #popup
window.popUpObj = window.open(url, '_blank', 'toolbar=0,status=0,resizable=0,location=0,menuBar=0,scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
#javascript #modal #popup
Tech C**P
How 3rd Party Logins work like Facebook, Google, etc? In order to understand this concept you need to read a little bit about OAuth 2.0 flow. The flow that frontiers use in order to get access token is called Implicit Flow in this scenario in one go…
Read a little bit more about
- https://developer.okta.com/authentication-guide/implementing-authentication/implicit
#oauth #oauth2 #implicit_flow
Implicit Flow
here:- https://developer.okta.com/authentication-guide/implementing-authentication/implicit
#oauth #oauth2 #implicit_flow
Okta
Implicit Flow | Okta Developer
Secure, scalable, and highly available authentication and user management for any app.
Tech C**P
How 3rd Party Logins work like Facebook, Google, etc? In order to understand this concept you need to read a little bit about OAuth 2.0 flow. The flow that frontiers use in order to get access token is called Implicit Flow in this scenario in one go…
Facebook
implicit flow example:- https://dzone.com/articles/oauth2-implicit-grant-flow-example-using-facebook
#oauth #facebook #implicit_flow
dzone.com
OAuth2 Implicit Grant Flow - Example Using Facebook OAuth2 API - DZone Security
Learn how to use the OAuth2 implicit grant flow in an untrusted client, such as a pure HTML or JavaScript application. This tutorial shows how with sample code.
https://www.confluent.io/blog/beginners-perspective-kafka-streams-building-real-time-walkthrough-detection?mkt_tok=eyJpIjoiTXpoak1USTRZVEF5TjJKayIsInQiOiIxb2dDdEpJallUVzhPeWF6T3I3NXBtNHFqYVh1V0xGa3hONHlKQ2ptc0JtVzFLXC8rbHQxVys5MWprQjNWZGpLUGR2N2hkS0poakNRdURhb0pndjd2QXVYOEtYbjczSFdRVGVSUHhGelVHXC9QT0t5QXNsYUdwSlgyN0ZcL3NjQmpkeSJ9
#kafka #streams #kafka_streams
#kafka #streams #kafka_streams
Confluent
A Beginner’s Perspective on Kafka Streams: Building Real-Time Walkthrough Detection | Confluent
Here at Zenreach, we use Kafka Streams to generate walkthrough counts. This post describes our use case, architecture and lessons we learned along the way.