Skip to content

Instantly share code, notes, and snippets.

@jmatsu
Last active February 5, 2019 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmatsu/2efe9c0e33673dbfaffcfbcd76b42b69 to your computer and use it in GitHub Desktop.
Save jmatsu/2efe9c0e33673dbfaffcfbcd76b42b69 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eux
mkdir -p tmp || :
cd tmp
: "${size:=240}"
: "${img_size:=$size}"
reponame="conference-app-2019"
page=1
rm contributors.json
while let "$page > 0"; do
curl -sL -o contributors.tmp.json "https://api.github.com/repos/DroidKaigi/$reponame/contributors?per_page=100&page=$page"
if let "$(ruby -rjson -e "puts JSON.parse(File.read('contributors.tmp.json')).size") > 0"; then
let "page=$page+1"
else
page="-100"
fi
if [[ ! -f "contributors.json" ]]; then
cp contributors.tmp.json contributors.json
else
cp contributors.json contributors.tmp2.json
ruby -rjson -e "puts (JSON.parse(File.read('contributors.tmp.json')) + JSON.parse(File.read('contributors.tmp2.json'))).to_json" > contributors.json
fi
done
while read login; do
iconName="$size/${login}.png"
if [[ ! -d "$size" ]]; then
mkdir -p "$size"
fi
if [[ ! -f "$iconName" ]]; then
curl -sL -o "$iconName" "https://github.com/$login.png?size=$size"
fi
done < <(ruby -rjson -e 'puts (JSON.parse(File.read("contributors.json")).map do |c| c["login"] end).join(" ")' | tr " " "\n")
cat<<EOF > index.html.erb
<html>
<head>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script>
function saveTable() {
html2canvas(document.querySelector("#table")).then(canvas => {
document.body.appendChild(canvas)
});
}
</script>
<style ="text/css">
div {
width:${img_size}px;
height:${img_size}px;
-webkit-border-radius:50%;
border-radius:50%;
border:1px solid #AAAAAA;
margin: 0 1px;
}
img {
width:${img_size}px;
height:${img_size}px;
border-radius:50%;
}
</style>
</head>
<body>
<table border="0" cellspacing="4px" cellpadding="0" id="table">
<% JSON.parse(File.read('./contributors.json')).each_slice(10) do |contributors| %>
<tr>
<% contributors.each do |contributor| %>
<td><div><img src="<%= "$size/#{contributor['login']}.png" %>"></div></td>
<% end %>
</tr>
<% end %>
</table>
<button onclick="saveTable()">Create a png</button>
</body>
</html>
EOF
ruby -rjson -rerb -e 'puts ERB.new(File.read("index.html.erb")).result(binding)' > index.html
open index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment