counter

PHP making a download counter without leaving the current page

感情迁移 提交于 2019-11-28 06:02:21
问题 I tried to create a download counter with PHP. The script, I have created, works, but when I click the download link, the script sends me to a blank page. Is it possible to stay on the page while downloading and counting? Here's my code of my download.php file: <?php $Down=$_GET['Down']; ?> <html> <head> <meta http-equiv="refresh" content="0;url=<?php echo $Down; ?>"> </head> <body> <?php $fp = fopen("counter.txt", "r"); $count = fread($fp, 1024); fclose($fp); $count = $count + 1; $fp = fopen

Rename the less frequent categories by “OTHER” python

放肆的年华 提交于 2019-11-28 04:14:19
问题 In my dataframe I have some categorical columns with over 100 different categories. I want to rank the categories by the most frequent. I keep the first 9 most frequent categories and the less frequent categories rename them automatically by: OTHER Example: Here my df : print(df) Employee_number Jobrol 0 1 Sales Executive 1 2 Research Scientist 2 3 Laboratory Technician 3 4 Sales Executive 4 5 Research Scientist 5 6 Laboratory Technician 6 7 Sales Executive 7 8 Research Scientist 8 9

Counting the number of times a value appears in an array

独自空忆成欢 提交于 2019-11-28 02:15:23
问题 So what's a good, simple algorithm to create a loop in C# where every time a certain value appears in an array it adds 1 to a counter in another array? For example I have this: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication22 { class Program { const int SIZE = 12; static void Main(string[] args) { int[] numbers = new int[SIZE] {5, 5, 5, 7, 7, 7, 9, 7, 9, 9, 9, 1}; string[] letters = new string[SIZE] { "m", "m", "s", "m", "s",

Why is Collections.counter so slow?

家住魔仙堡 提交于 2019-11-27 22:56:02
I'm trying to solve a Rosalind basic problem of counting nucleotides in a given sequence, and returning the results in a list. For those ones not familiar with bioinformatics it's just counting the number of occurrences of 4 different characters ('A','C','G','T') inside a string. I expected collections.Counter to be the fastest method (first because they claim to be high-performance, and second because I saw a lot of people using it for this specific problem). But to my surprise this method is the slowest ! I compared three different methods, using timeit and running two types of experiments:

PHP-MySQL-How to safely increment MySQL integer field?

妖精的绣舞 提交于 2019-11-27 20:50:36
问题 I want to increment a field value safely using php and mysql. What type of table/field must I use? Is there a minimum version of MySQL I must use? What's the sql code for this, safe transaction for MySQL? 回答1: By what type of "table" I assume you mean storage engine. Anything that supports mutations (i.e. not "archive" or "black hole") Any numeric field will do (tinyint, int, float, etc). That said, there's no special PHP code, just the SQL for incrementing the desired field: UPDATE table SET

Adding counters deletes keys

寵の児 提交于 2019-11-27 15:30:55
See below, why does the implementation of += blow away a key in my original counter? >>> c = Counter({'a': 0, 'b': 0, 'c': 0}) >>> c.items() [('a', 0), ('c', 0), ('b', 0)] >>> c += Counter('abba') >>> c.items() [('a', 2), ('b', 2)] I think that's impolite to say the least, there is quite a difference between "X was counted 0 times" and "we aren't even counting Xs". It seems like collections.Counter is not a counter at all, it's more like a multiset. But counters are a subclass of dict and we're allowed to construct them with zero or negative values: Counter(a=0, b=-1) . If it's actually a "bag

How to count the number of words in a sentence, ignoring numbers, punctuation and whitespace?

ぃ、小莉子 提交于 2019-11-27 11:45:45
How would I go about counting the words in a sentence? I'm using Python. For example, I might have the string: string = "I am having a very nice 23!@$ day. " That would be 7 words. I'm having trouble with the random amount of spaces after/before each word as well as when numbers or symbols are involved. str.split() without any arguments splits on runs of whitespace characters: >>> s = 'I am having a very nice day.' >>> >>> len(s.split()) 7 From the linked documentation: If sep is not specified or is None , a different splitting algorithm is applied: runs of consecutive whitespace are regarded

JavaScript Flip Counter

女生的网名这么多〃 提交于 2019-11-27 10:56:56
问题 I would like to include a flip counter on my site, similar to what Apple was using for their 1 billion app countdown. Can anyone get their JavaScript to work standalone? If anyone can provide working code, that would be great. 回答1: They're using a combination of CSS and JavaScript. The flip animation is powered by a CSS Sprite-like technique. First of all, they have a very tall image called filmstrip.png that contains every flip "state" for each number (0 to 9; have a look at a scaled-down

Counter increment in Bash loop not working

♀尐吖头ヾ 提交于 2019-11-27 10:26:46
I have the following simple script where I am running a loop and want to maintain a COUNTER . I am unable to figure out why the counter is not updating. Is it due to subshell thats getting created? How can I potentially fix this? #!/bin/bash WFY_PATH=/var/log/nginx WFY_FILE=error.log COUNTER=0 grep 'GET /log_' $WFY_PATH/$WFY_FILE | grep 'upstream timed out' | awk -F ', ' '{print $2,$4,$0}' | awk '{print "http://domain.com"$5"&ip="$2"&date="$7"&time="$8"&end=1"}' | awk -F '&end=1' '{print $1"&end=1"}' | ( while read WFY_URL do echo $WFY_URL #Some more action COUNTER=$((COUNTER+1)) done ) echo

Get loop counter/index using for…of syntax in JavaScript

流过昼夜 提交于 2019-11-27 10:18:09
Caution: question still applies to for…of loops.> Don't use for…in to iterate over an Array , use it to iterate over the properties of an object. That said, this I understand that the basic for…in syntax in JavaScript looks like this: for (var obj in myArray) { // ... } But how do I get the loop counter/index ? I know I could probably do something like: var i = 0; for (var obj in myArray) { alert(i) i++ } Or even the good old: for (var i = 0; i < myArray.length; i++) { var obj = myArray[i] alert(i) } But I would rather use the simpler for-in loop. I think they look better and make more sense.