Skip to content

Instantly share code, notes, and snippets.

@LeaveNhA
Last active May 2, 2022 00:53
Show Gist options
  • Save LeaveNhA/14c1635b4532daaaa57331c6286145b9 to your computer and use it in GitHub Desktop.
Save LeaveNhA/14c1635b4532daaaa57331c6286145b9 to your computer and use it in GitHub Desktop.
List of the language I use, yet;
// GH api is so annoying. It might show partial data.
// The structure is;
// [[language name, _, percent in total],,,]
await fetch('https://api.github.com/users/LeaveNhA/repos?per_page=1000')
.then(r => r.json())
.then(rs => rs.map(r => r.languages_url))
.then(rs => rs.map(async (r) => (await (await fetch(r)).json())))
.then(lrs => Promise.all(lrs))
.then(ls => ls.filter(l => !l.hasOwnProperty('message')))
.then(ls => ls.map(l => Object.entries(l)))
.then(lrs => lrs.reduce((acc, l) => [...acc, ...l], []))
.then(la => la.reduce((acc, l) => (acc.hasOwnProperty(l[0]) ? {...acc, [l[0]]: acc[l[0]] + l[1]} : {...acc, [l[0]]: l[1]} ), {}))
.then(lo => Object.entries(lo))
.then(les => les.filter(([languageName]) => languageName != 'HTML'))
.then(les => les.sort(([, l1], [, l2]) => l1 === l2 ? 0 : (l1 > l2 ? 1 : -1)))
.then(ls => [ls.reduce((a, [, b]) => a+b, 0), ls])
.then(([total, ls]) => ls.map(l => [...l, (l[1] / total).toFixed(4)]))
.then(lsa => lsa.sort(([, l1], [, l2]) => l1 === l2 ? 0 : (l1 > l2 ? 1 : -1)))
.then(a => a.reverse())
@LeaveNhA
Copy link
Author

LeaveNhA commented May 2, 2022

An example output;

[
  [ 'HTML', 2723466, '0.25' ],
  [ 'Clojure', 2567634, '0.23' ],
  [ 'JavaScript', 993073, '0.09' ],
  [ 'Java', 345018, '0.03' ],
  [ 'C++', 324574, '0.03' ],
  [ 'Ruby', 275410, '0.03' ],
  [ 'CSS', 264886, '0.02' ],
  [ 'C#', 238297, '0.02' ],
  [ 'Shell', 222799, '0.02' ],
  [ 'Go', 216089, '0.02' ],
  [ 'Objective-C', 167744, '0.02' ],
  [ 'Raku', 167660, '0.02' ],
  [ 'Julia', 161236, '0.01' ],
  [ 'Common Lisp', 154983, '0.01' ],
  [ 'Elixir', 150344, '0.01' ],
  [ 'Haskell', 148435, '0.01' ],
  [ 'Swift', 145825, '0.01' ],
  [ 'C', 131211, '0.01' ],
  [ 'Kotlin', 107928, '0.01' ],
  [ 'Lua', 104352, '0.01' ],
  [ 'F#', 89795, '0.01' ],
  [ 'Erlang', 89200, '0.01' ],
  [ 'MATLAB', 88174, '0.01' ],
  [ 'TeX', 77239, '0.01' ],
  [ 'Emacs Lisp', 74497, '0.01' ],
  [ 'D', 69470, '0.01' ],
  [ 'Perl', 68169, '0.01' ],
  [ 'PHP', 65149, '0.01' ],
  [ 'Brainfuck', 62866, '0.01' ],
  [ 'Haxe', 57681, '0.01' ],
  [ 'Logtalk', 53974, '0.00' ],
  [ 'Groovy', 48129, '0.00' ],
  [ 'Dart', 47205, '0.00' ],
  [ 'LiveScript', 44264, '0.00' ],
  [ 'Makefile', 43322, '0.00' ],
  [ 'CoffeeScript', 41672, '0.00' ],
  [ 'Elm', 40883, '0.00' ],
  [ 'Chapel', 39146, '0.00' ],
  [ 'Hack', 38644, '0.00' ],
  [ 'Fortran', 29599, '0.00' ],
  [ 'Nix', 27905, '0.00' ],
  [ 'Forth', 26839, '0.00' ],
  [ 'Standard ML', 21604, '0.00' ],
  [ 'Python', 21593, '0.00' ],
  [ 'ColdFusion', 18448, '0.00' ],
  [ 'ASL', 18419, '0.00' ],
  [ 'Hy', 17909, '0.00' ],
  [ 'Factor', 16258, '0.00' ],
  [ 'CMake', 13161, '0.00' ],
  [ 'OCaml', 11806, '0.00' ],
  [ 'Inform 7', 7938, '0.00' ],
  [ 'PowerShell', 7794, '0.00' ],
  [ 'Racket', 7445, '0.00' ],
  [ 'R', 4997, '0.00' ],
  [ 'PureScript', 3508, '0.00' ],
  [ 'Dockerfile', 2330, '0.00' ],
  [ 'Smarty', 2072, '0.00' ],
  [ 'Batchfile', 1415, '0.00' ]
]

@LeaveNhA
Copy link
Author

LeaveNhA commented May 2, 2022

HTML is like an unwanted child, you have it but you want to keep it in it's room when you want to show-off;

[
  [ 'Clojure', 2565887, '0.3232' ],
  [ 'JavaScript', 700723, '0.0883' ],
  [ 'Java', 345018, '0.0435' ],
  [ 'C++', 324574, '0.0409' ],
  [ 'Ruby', 275410, '0.0347' ],
  [ 'C#', 238297, '0.0300' ],
  [ 'Shell', 221080, '0.0279' ],
  [ 'Go', 216089, '0.0272' ],
  [ 'CSS', 212508, '0.0268' ],
  [ 'Objective-C', 167744, '0.0211' ],
  [ 'Raku', 167660, '0.0211' ],
  [ 'Julia', 161236, '0.0203' ],
  [ 'Common Lisp', 154983, '0.0195' ],
  [ 'Elixir', 153786, '0.0194' ],
  [ 'Haskell', 148435, '0.0187' ],
  [ 'Swift', 145825, '0.0184' ],
  [ 'C', 131211, '0.0165' ],
  [ 'Kotlin', 107928, '0.0136' ],
  [ 'Lua', 94642, '0.0119' ],
  [ 'F#', 89795, '0.0113' ],
  [ 'Erlang', 89200, '0.0112' ],
  [ 'MATLAB', 88174, '0.0111' ],
  [ 'TeX', 77239, '0.0097' ],
  [ 'Emacs Lisp', 74497, '0.0094' ],
  [ 'D', 69470, '0.0088' ],
  [ 'Perl', 68169, '0.0086' ],
  [ 'PHP', 65149, '0.0082' ],
  [ 'Brainfuck', 62866, '0.0079' ],
  [ 'Haxe', 57681, '0.0073' ],
  [ 'Logtalk', 53974, '0.0068' ],
  [ 'Groovy', 48129, '0.0061' ],
  [ 'Dart', 47205, '0.0059' ],
  [ 'LiveScript', 44264, '0.0056' ],
  [ 'Makefile', 43322, '0.0055' ],
  [ 'CoffeeScript', 41672, '0.0052' ],
  [ 'Elm', 40883, '0.0052' ],
  [ 'Chapel', 39146, '0.0049' ],
  [ 'Hack', 38644, '0.0049' ],
  [ 'Fortran', 29599, '0.0037' ],
  [ 'Standard ML', 28379, '0.0036' ],
  [ 'Nix', 27905, '0.0035' ],
  [ 'Forth', 26839, '0.0034' ],
  [ 'Python', 21593, '0.0027' ],
  [ 'ColdFusion', 18448, '0.0023' ],
  [ 'ASL', 18419, '0.0023' ],
  [ 'Hy', 17909, '0.0023' ],
  [ 'Factor', 16258, '0.0020' ],
  [ 'CMake', 13161, '0.0017' ],
  [ 'OCaml', 11806, '0.0015' ],
  [ 'PureScript', 8460, '0.0011' ],
  [ 'Inform 7', 7938, '0.0010' ],
  [ 'PowerShell', 7794, '0.0010' ],
  [ 'R', 4997, '0.0006' ],
  [ 'Dockerfile', 2330, '0.0003' ],
  [ 'Smarty', 2072, '0.0003' ],
  [ 'Batchfile', 1415, '0.0002' ]
]

Also, percents are fixed to be 4 digits, not 2. Yet, it's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment