How to get only numbers in textbox using
#javascript #jquery #input #number
jQuery
?// Restricts input for each element in the set of matched elements to the given inputFilter.
(function($) {
$.fn.inputFilter = function(inputFilter) {
return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("oldValue")) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
}
});
};
}(jQuery));
// restrict input to receive just numbers
$("#my_input_num").inputFilter(function(value) {
return /^\d*$/.test(value);
});
#javascript #jquery #input #number
In
The response differs based on the given scope on the first login step. Mine was set to the below:
#google #login_with_google #oauth #scope #userinfo #oauth2
Google OAUTH 2.0
in case you get a token from Google Login
you can get user's information for that token by sending a simple GET
request to the following URL:https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=YOUR_GOOGLE_TOKEN
The response differs based on the given scope on the first login step. Mine was set to the below:
https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
#google #login_with_google #oauth #scope #userinfo #oauth2
Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.
Examples:
#question #codewars #algorithm
Examples:
pig_it('Pig latin is cool') # igPay atinlay siay oolcay
pig_it('Hello world !') # elloHay orldway !
#question #codewars #algorithm
How to find the query associated with a queryset in
Sometime you want to know how a Django ORM makes our queries execute or what is the corresponding SQL of the code you are writing. This is very strightforward. Youn can get str of any queryset.query to get the sql.
You have a model called Event. For getting all records, you will write something like Event.objects.all(), then do str(queryset.query)
Example 2:
#python #django #orm
Django ORM
?Sometime you want to know how a Django ORM makes our queries execute or what is the corresponding SQL of the code you are writing. This is very strightforward. Youn can get str of any queryset.query to get the sql.
You have a model called Event. For getting all records, you will write something like Event.objects.all(), then do str(queryset.query)
>>> queryset = Event.objects.all()
>>> str(queryset.query)
SELECT "events_event"."id", "events_event"."epic_id",
"events_event"."details", "events_event"."years_ago"
FROM "events_event"
Example 2:
>>> queryset = Event.objects.filter(years_ago__gt=5)
>>> str(queryset.query)
SELECT "events_event"."id", "events_event"."epic_id", "events_event"."details",
"events_event"."years_ago" FROM "events_event"
WHERE "events_event"."years_ago" > 5
#python #django #orm
https://ux.stackexchange.com/questions/123222/when-your-page-has-no-results-what-do-you-show
#ux #no_result #action_button
#ux #no_result #action_button
User Experience Stack Exchange
When your page has no results, what do you show?
I am paginating a data table and have different views in my application where each view has its own rows. Some views may have data, some may not
Showing 1-0 of 0 Page 1 of 0
is what I am showing o...
Showing 1-0 of 0 Page 1 of 0
is what I am showing o...
How to convert
#javascript #ByteArray #PDF #Uint8Array #Blob #jQuery
ByteArray
to PDF
and then upload it via jQuery
?var docData = [ yourByteArray ];
var blob = new Blob([new Uint8Array(docData)], { type: 'application/pdf' });
// Now create form to upload the file
var formData = new FormData();
formData.append("file", blob);
// Let's now upload the file
$.ajax({
type: 'POST',
url: 'https://www.YOUR-UPLOAD-FILE-ENDPOINT.com/storage',
beforeSend: request => set_ajax_headers(request),
data: formData,
processData: false,
contentType: false
}).done(function(data) {
console.log('File is uploaded!');
});
NOTE:
function set_ajax_headers
is a function that sets headers on the given request.#javascript #ByteArray #PDF #Uint8Array #Blob #jQuery
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example:
#python #codewars
domain_name("https://github.com/carbonfive/raygun") == "github"
domain_name("https://www.zombie-bites.com") == "zombie-bites"
domain_name("https://www.cnet.com") == "cnet"
#python #codewars
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