Skip to content

Instantly share code, notes, and snippets.

@itskhaledmohammad
Last active January 6, 2018 16:20
Show Gist options
  • Save itskhaledmohammad/2cd18d8465725c74b4c1923d069cb8e3 to your computer and use it in GitHub Desktop.
Save itskhaledmohammad/2cd18d8465725c74b4c1923d069cb8e3 to your computer and use it in GitHub Desktop.
This script shows you some cool stats of your GitHub profile in your browser's console.
/*
* Author: Khaled Mohammad
* Dated: 6th January, 2018
*
* How to use:
* 1.Go to your github profile page: github.com/<yourusername>/
* 2.Open console by pressing F12.
* 3.Paste the code below.
* 4.It will show you some juicy stats about your profile.Tadaaa!
*
* You can try this on other's profile too.
*/
// Clearing the console.
clear();
// This function finds the median of an array.
function findMedian(arr){
if(arr.length % 2 == 0) return (arr[parseInt(arr.length / 2)] + arr[parseInt((arr.length / 2) - 1)]) / 2;
return arr[parseInt(arr.length / 2)];
}
// Variables
var color = "#ebedf0";
var days = document.querySelectorAll(".day");
var spaces = "";
var i = 0, sepDays = [], intCount = 0, totalCommits = 0;
// Setting the number of spaces that will be needed according to width.
for(var i = 0; i < (window.innerWidth / 4); i++) spaces += " ";
var newLine = spaces + "\n";
// Getting all the days.
for(i = 0; i < days.length; i++){
if(days[i].getAttribute("fill") != color){
intCount = parseInt(days[i].getAttribute("data-count"));
totalCommits += intCount;
sepDays.push(intCount);
}
}
// Sorting the array in ascending order.
sepDays.sort(function(a, b){ return a - b; });
// Showing the stats.
console.log("%cGithub Stats:" + newLine +
"Total Commits: " + totalCommits + newLine +
"Number of days with atleast 1 commit: " + sepDays.length + newLine +
"Average daily commits: " + (totalCommits / days.length) + newLine +
"Average commits the days you decided to commit: " + (totalCommits / sepDays.length) + newLine +
"Maximum nunmber of commits done in a single day: " + Math.max(...sepDays) + newLine +
"Minimum number of commits you have done 50% of the days out of the days you committed: " + findMedian(sepDays) + newLine,
'background: #000; color: #20C20E; font-size: 20px');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment