Created
November 28, 2023 04:58
-
-
Save sbauch/390d92bb873049d110e4898388b8faae to your computer and use it in GitHub Desktop.
ghost-writer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A,111111010011111 | |
B,111111010101110 | |
C,111111000110001 | |
D,111111000101110 | |
E,111111010110101 | |
F,111111010010000 | |
G,011101010110010 | |
H,111110010011111 | |
I,100011111110001 | |
J,100111111110000 | |
K,111110010011011 | |
L,111110000100001 | |
M,1111101000001100100011111 | |
N,11111010000010011111 | |
O,111111000111111 | |
P,111111010011100 | |
Q,0 | |
R,111111011011101 | |
S,010011010110010 | |
T,100001111110000 | |
U,111100000111110 | |
V,111100000111110 | |
W,1111100010011000001011111 | |
X,100010111010001 | |
Y,111000011111100 | |
Z,0 | |
0,111111000111111 | |
1,1000011111 | |
2,101111010111101 | |
3,101011010111111 | |
4,111000010011111 | |
5,111011010110111 | |
6,111111010110111 | |
7,100001000011111 | |
8,111111010111111 | |
9,111001010011111 | |
!,0000011101 | |
?,010001010101100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Number of commits to make for an OFF square | |
OFF_COMMITS=1 | |
# Number of commits for an ON square - increase this number if | |
# you have many commits in the time period so the text stands out from | |
# your other commits | |
ON_COMMITS=10 | |
# Date to start writing squares - must be a Sunday | |
d="2001-01-07" | |
[email protected] | |
gitUsername=your_username | |
if [ $# -eq 0 ]; then | |
echo "No message supplied" | |
exit 1 | |
fi | |
if ((${#1} > 15)); then | |
echo "The message is longer than 15 characters" | |
exit 1 | |
fi | |
if [[ ! $1 =~ ^[A-Z0-9!?[:space:]]+$ ]]; then | |
echo "The message contains invalid characters" | |
exit 1 | |
fi | |
declare -A font_map | |
while IFS=',' read -r key value; do | |
font_map["$key"]="$value" | |
done <alphabet.txt | |
write_date() { | |
commitDate=$1 | |
for ((commit = 0; commit < $ON_COMMITS; commit++)); do | |
echo "$commitDate-$commit" >commit.txt | |
git add . | |
GIT_COMMITTER_DATE="$commitDate 03:0$commit" git commit --date="$commitDate 03:0$commit" -m "commit $commit on $commitDate" &>/dev/null | |
done | |
} | |
write_empty_date() { | |
commitDate=$1 | |
for ((commit = 0; commit < $OFF_COMMITS; commit++)); do | |
echo "$commitDate-$commit" >commit.txt | |
git add . | |
GIT_COMMITTER_DATE="$commitDate 03:0$commit" git commit --date="$commitDate 03:0$commit" -m "commit $commit on $commitDate" &>/dev/null | |
done | |
} | |
add_space() { | |
spaceDate=$1 | |
for ((blankRow = 0; blankRow < 15; blankRow++)); do | |
write_empty_date $spaceDate | |
spaceDate=$(date -j -v+1d -f "%Y-%m-%d" "$spaceDate" "+%Y-%m-%d") | |
done | |
} | |
reinit_git() { | |
rm -rf .git | |
git init &>/dev/null | |
git config user.name $gitUsername | |
git config user.email $gitEmail | |
} | |
process_char() { | |
map=$1 | |
targetDate=$2 | |
length=$3 | |
for ((c = 0; c < length; c++)); do | |
write_empty_date $targetDate | |
# if we are at the top of a column, add 1 day space | |
if [ $((c % 5)) -eq 0 ]; then | |
targetDate=$(date -j -v+1d -f "%Y-%m-%d" "$targetDate" "+%Y-%m-%d") | |
fi | |
if [ ${map:$c:1} -eq 1 ]; then | |
write_date $targetDate | |
else | |
write_empty_date $targetDate | |
fi | |
# add one day to date | |
targetDate=$(date -j -v+1d -f "%Y-%m-%d" "$targetDate" "+%Y-%m-%d") | |
# bottom row + loop around | |
if [ $((c % 5)) -eq 4 ]; then | |
write_empty_date $targetDate | |
targetDate=$(date -j -v+1d -f "%Y-%m-%d" "$targetDate" "+%Y-%m-%d") | |
fi | |
# if last column, add 1 column of space | |
if [ $c -eq $((length - 1)) ]; then | |
for ((blankRow = 0; blankRow < 7; blankRow++)); do | |
write_empty_date $targetDate | |
targetDate=$(date -j -v+1d -f "%Y-%m-%d" "$targetDate" "+%Y-%m-%d") | |
done | |
fi | |
done | |
} | |
text=$1 | |
#replace spaces with underscores | |
text=${text// /_} | |
#Create a repo | |
mkdir $text &>/dev/null | |
cd $text | |
reinit_git | |
echo "text is $text" | |
add_space $d | |
d=$(date -j -v+7d -f "%Y-%m-%d" "$d" "+%Y-%m-%d") | |
for ((charIndex = 0; charIndex < ${#text}; charIndex++)); do | |
char=${text:$charIndex:1} | |
if [ $char == "_" ]; then | |
add_space $d | |
d=$(date -j -v+7d -f "%Y-%m-%d" "$d" "+%Y-%m-%d") | |
continue | |
fi | |
echo "processing $char" | |
map=${font_map["$char"]} | |
n=${#map} | |
cols=$((n / 5)) | |
process_char $map $d $n | |
git remote add origin [email protected]:gitffiti/studio.git | |
git push -u origin main --force | |
reinit_git | |
# add 7 days for each col | |
for ((col = 0; col <= cols; col++)); do | |
d=$(date -j -v+7d -f "%Y-%m-%d" "$d" "+%Y-%m-%d") | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bash script and alphabet for writing text to github contribution graphs
i was too lazy to do Q and Z
i also only used this on a fresh github account