Got my account restored yesterday and I decided to write something interesting this morning.

Recently, some devs are obsessed with GitHub activity graphs(even some employers) , but this is totally absurd.

Why ?

Let’s write a script in 1hr or less….. #Thread #100DaysOfCode
First off, how does GitHub build the graph ?
A quick peek into the contribution graph shows that it’s purely based on commits.

If it’s built on commits, then shouldn’t we be able to write a simple script to commit on our behalf as a cron job while we sleep?

Ok, let’s go!
First off, what’s the least work to be done ?

For each day :
1. Create a file
2. Make some changes to the file
3. Commit (as many as you prefer)
4. Push to GitHub
Let's call our project gitconfreakyfreaky or gitconfreak for short.

Project initialized!
Now we'll need at least three functions

1. create_file
2. commit_changes
3. push_changes
OK let's write an implementation for create_file.

we'll create a text file, write a commit_number and the date and time, then close the file.
To write an implementation for commit_changes, python’s “subprocess” will come in handy to execute our
“git add .” &&
“git commit" commands.

At this point we are technically done with our script.
Now let’s top it off with our push_changes function.

We’ll need only one line for this one :

“subprocess. run("git push -u origin master -f", check=True, shell=True)”
For each day :

we want to specify the number of commits as a variable, create a for-loop that runs create_file & commit_changes n times, then we finally push it with subprocess to a repo we create.
Now it’s time to test if all of that nonsense code makes sense and runs as expected.

Just add your Github ssh key to your local environment and add this script.
Whew….first error, as expected…but it’s pretty basic, let’s fix this
Whew, success !

It committed .idea IDE folder in addition, who cares?!!

Now we can run 3 or 1000 commits per day if we wish!

Next, let’s wrap this in a cron job that runs everyday.
I’m hungry, let me go get something to eat.
You can follow @ace_rbk.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.