Count the number of words for each contributor [closed] - github

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I count the number of words that each contributor wrote in a repository ?

It is best solved on a local clone of that GitHub, in order to analyze the git log and check each contributor.
See "getting contributor stats", based on:
git log --author="Jared Barboza" --pretty=tformat: --numstat | \
grep -v public/javascripts/jquery | \
gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END \
{ printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
But that is for lines added/removed for a given contributor.
(a bit like in "Git: How to estimate a contribution of a person to my project in terms of added/changed lines of code?")
You can combined a similar approach with the one described in "Quantifying the amount of change in a git diff?".
Or you can use a dedicated program for that, like git-wordcount.

Related

Should I use sed, awk, perl, for altering text spanning multiple lines and selecting only the info needed? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm working on a project for class where we take a file full of lines describing classes like the one below
CSC 1010 - COMPUTERS & APPLICATIONS
Computers and Applications. Prerequisite: high school Algebra II. History of computers, >hardware components, operating systems, applications software, data communication.
3.000 Credit hours
and turn it into
CSC1010,COMPUTERS & APPLICATIONS,3
I used:
sed -n 's/^CSC /CSC/p' courses.txt > practice.txt
which outputs:
CSC1010 - COMPUTERS & APPLICATIONS
CSC1310 - INTRO COMP PROGRAMMING NON-MAJ
CSC2010 - INTRO TO COMPUTER SCIENCE
CSC2310 - PRIN OF COMPUTER PROGRAMMING
CSC2320 - FUND OF WEBSITE DEVELOPMENT
CSC2510 - THEOR FOUNDATIONS OF COMP SCI
CSC3010 - HISTORY OF COMPUTING
CSC3210 - COMPUTER ORG & PROGRAMMING
CSC3320 - SYSTEM-LEVEL PROGRAMMING
CSC3330 - C++ PROGRAMMING
CSC3410 - DATA STRUCTURES-CTW
CSC4110 - EMBEDDED SYSTEMS
CSC4120 - INTRODUCTION TO ROBOTICS
and I also used:
sed '/\.000 Course hours//p' courses.txt > courses10.txt
which outputs:
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
My problem is trying to select whether the sed, awk, or perl would be better. So, far I've used sed to eliminate the lines that are not composed either of the course title or the number of credit hours. As you saw above. I was hoping to use a regular expression to sort through the file and get each line that started with "CSC" or contained ".000 Course hours". I figured that after I got that output I could use a command in the sed to remove the new line from the end of the lines starting with the CSC and replace that with a comma. After that I would replace the backslash with a comma. However, to do that I think I would need to use an extended expression so sed would probably be out. The regular expression I was considering using is (^CSC |[0-9]\.000). So, should I be doing this in sed, awk, or perl. If you could please include your reasoning as to why it would be more efficient to use whatever method you suggest.
In Perl:
while (<>) {
chomp;
print if s/^CSC\s+/CSC/ and s/\s+-\s+/,/;
printf ",%.0f\n", $1 if /^([\d.]+)\s+Credit hours/;
}
I'd go with awk because you want to match and reformat lines and awk is perfect for this:
/CSC/ { # Lines that match CSC
split($0,a,"- ") # Split the line around the hyphen and following space
gsub(/ /,"",a[1]) # Remove the spaces from the first part of the split
printf a[1]","a[2] # Print the line in required format
}
/Credit hours/ { # Lines that match Credit hours
printf ",%i\n",$1 # Print the integer value of credit hours
}
Demo:
awk '/CSC/{split($0,a,"- ");gsub(/ /,"",a[1]);printf a[1]","a[2]}/Credit hours/{printf ",%i\n",$1}' file
CSC1010,COMPUTERS & APPLICATIONS,3
I prefer awk to Perl, which has no advantage (or disadvantage) for this. Using sed would be a regexp hack so I'd stay away from a sed solution.

Convert a mixed string to UTF16 with PHP [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a string in PHP like this:
INPUT = "Γιώργο αν στείλεις αυτό ακριβώς (:
Its a mixed string with GREEK and LATIN characters at the same time. I want all characters in a given string to be converted to this string
OUTPUT = 0022039303B903CE03C103B303BF002003B103BD002003C303C403B503AF03BB03B503B903C2002003B103C503C403CC002003B103BA03C103B903B203CE03C200200028003A
How can I convert the input to this kind of output?
It took me a while to figure out but it seems that what you want to do is to convert a UTF-8 string to an uppercase binary dump of its UTF-16 representation. It's as simple as this:
$input = '"Γιώργο αν στείλεις αυτό ακριβώς (:';
$output = mb_strtoupper(bin2hex(mb_convert_encoding($input, 'UTF-16BE', 'UTF-8')));
The BE suffix indicates Big Endian, which seems to be the expected byte order according to your example.
Have you tried iconv? Maybe something like this:
(EDIT) i understand your main goal is to be able this converted string to be transported via http to your service, in that case you can use base64_encode() on the result.
see the complete code example:
<?php
$string = str_replace(' ', '', "Γιώργο αν στείλεις αυτό ακριβώς");
$converted = iconv('UTF-8', 'UTF-16', $string);
$encoded = base64_encode($converted);
var_dump($encoded);
var_dump(iconv('UTF-16', 'UTF-8', base64_decode($encoded)));
?>
You will get:
encoded: string '/v8DkwO5A84DwQOzA78DsQO9A8MDxAO1A68DuwO1A7kDwgOxA8UDxAPMA7EDugPBA7kDsgPOA8I=' (length=76)
decoded: string 'Γιώργοανστείλειςαυτόακριβώς' (length=54)

How to compare two dates using UNIX commands [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have dates like this
Date1="Wed Oct 21 13:05:14 2012"
Date2="Wed Nov 21 12:55:30 2010"
Date3="Wed Nov 21 14:22:30 2012"
How do I find out the latest date?
The unix date command can convert date formats, see for example here. So in bash, you'd do something like this:
#!/bin/sh
Date1="Wed Oct 21 13:05:14 2012"
Date2="Wed Nov 21 12:55:30 2010"
Date3="Wed Nov 21 14:22:30 2012"
ts1=`date -d"${Date1}" +%Y%m%d%H%M%S`
ts2=`date -d"${Date2}" +%Y%m%d%H%M%S`
ts3=`date -d"${Date3}" +%Y%m%d%H%M%S`
latest=ts1
if [ $ts2 -gt $ts1 ]; then
latest=ts2
fi
if [ $ts3 -gt $ts1 ]; then
latest=ts3
fi
echo "Latest date is ${latest}"

add an option to the perl script command line [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
assume this is file.txt
Name:Lab1:Lab2:Lab3:Lab4:Lab5:Lab6:Exam1:Exam2:Final
Annette Adams :8:24:19:24:10:12:43:35:98
Mary Beard:9:30:19:23:10:14:29:39:87
Antoinette Brown:9:16:18:22:9:12:19:31:79
.
.
.
is it possible in Perl to write a script with some options which user can pass to command line and get the result.
for example getAverage.pl -l 3 file.txt prints the average of Lab3 Marks.
if it is possible what is the overall process?
Try http://perldoc.perl.org/Getopt/Long.html From the documentation:
The Getopt::Long module implements an extended getopt function called
GetOptions(). This function adheres to the POSIX syntax for command
line options, with GNU extensions. In general, this means that options
have long names instead of single letters, and are introduced with a
double dash "--". Support for bundling of command line options, as was
the case with the more traditional single-letter approach, is provided
but not enabled by default.
For general information about accessing command line options in Perl, read the perlvar documentation: http://perldoc.perl.org/perlvar.html#$ARGV
I put together a quick and dirty solution in python. Should be easy to port it to perl.
import sys
lines = open("file.txt",'r').readlines()
if len(sys.argv) > 2 and sys.argv[1] == "-l":
try:
number = int(sys.argv[2])
except:
print "Input a number after the -l switch."
average = 0
for i in lines:
try:
average += int(i.split(":")[number])
except:
pass
average /= 3
print "The average score for %s is %d" \
%(lines[0].split(":")[number], average)
else:
print "Computer says no."

BIGINT scalar function [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to??
Create a scalar function that returns a bigint.
The function takes 2 inputs of bigint.
The function multiplies the inputs and returns the result.
Thank You,
How about something like this:
CREATE FUNCTION [dbo].[testbigint]
(
#int1 bigint,
#int2 bigint
)
RETURNS bigint
AS
BEGIN
-- Declare the return variable here
DECLARE #returnVal bigint
set #returnVal = #int1* #int2
-- Return the result of the function
RETURN #returnVal
END