Skip to main content

Embedding Github code into your Blogger blog

When I have thought about writing my own programming blog, it seems very easy to me I just have to login into Blogger using my gmail account. But in process of writing my first blog I  have faced a lots of problems like how to format my content how to insert images and a lots of things, But the major one is how to enter my my hand written well formatted code into my blog. So I have tried to just copy paste the code into Compose mode and also tried to embed it into HTML but I was not able to maintain the format of my code.

So have done some research over the net and found a lots of ways to do so there are lots of JS plugins to do so etc. But one way seems to be very cool and  easy to me is posting your code on Github Gist and then making reference from your blog. We should not confuse gist with git, both are separate things. Git is a popular source code management system while Gist is really an awesome way to share your well formatted code with anyone on any platform with just a javascript call, and below I am going to show you how to do that.

You can refer your complete gist repo or you can choose any file from your repo to do so. To do this first of all you need to create a Github account, it is very easy and you can found a lots of tutorials for that even on the official Github website. Then you need to make a gist repository for that you can also find tutorial on this link about gists.

Lets walk through below steps and share your github code on your blog

First of all you need to create a gist repository on e.g. this is one of my gist repo CustomSolrRepo.
you can create your Gist repo online on this link, all you need to do is just enter a filename with extension on top and then  add some code below and then click on create public gist, you can also create a secret gist if you want.




Now you need to copy the complete script tag which is just right to Embed dropdown box.



















And paste it in your blog, but you need to open your blog in HTML mode and you should paste it at the end after any tag. You might have created more than one file in your gist repository so to embed code of only one file into your you need to mention that file as argument inside the script tag e.g.

<script src="https://gist.github.com/njnareshjoshi/98eafbaaa55b919f551e.js?file=CustomSolrRepoApp.java"></script>

Same I am doing in blog here



And you can the output here


However when you will switch to Compose mode again you will not be able to see that but you can see that in Preview mode.

Comments

  1. Free easy & simple way to learn programming online we provide niit projects, assignments, cycle tests and much more..
    visit ====>>> https://githubhelp.blogspot.in/

    ReplyDelete
  2. Thanks bro ..
    Really Helpful post.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why Single Java Source File Can Not Have More Than One public class

According to Java standards and common practices we should declare every class in its own source file. And even if we declare multiple classes in the single source file (.java) still each class will have its own class file after compilation. But the fact is that we can declare more than one class in a single source file with below constraints, Each source file should contain only one public class and the name of that public class should be similar to the name of the source file. If you are declaring the main method in your source file then main should lie in that public class If there is no public class in the source file then main method can lie in any class and we can give any name to the source file. If you are not following 1st constraint then you will receive a compilation error saying “ The public type A must be defined in its own file ”.  While if you are not following the second constraint you will receive an error “ Error: Could not find or load main class User ” after exec

AutoWiring Spring Beans Into Classes Not Managed By Spring Like JPA Entity Listeners

In my previous article JPA Auditing: Persisting Audit Logs Automatically using EntityListeners , I have discussed how we can use Spring Data JPA automate Auditing and automatically create audit logs or history records and update CreatedBy, CreatedDate, LastModifiedBy, LastModifiedDate properties. So in order to save history records for our File entity, we were trying to auto-wire EntityManager inside our FileEntityListener class and we have come to know that we can not do this. We can not inject any Spring-managed bean in the EntityListener because EntityListeners are instantiated by JPA before Spring inject anything into it. EntityListeners are not managed Spring so Spring cannot inject any Spring-managed bean e.g. EntityManager in the EntityListeners. And this case is not just with EntityListeners, you can not auto wire any Spring-managed bean into another class (i.e. utility classes) which is not managed by Spring. Because it is a very common problem and can also arise with other c

How Does JVM Handle Method Overloading and Overriding Internally

In my previous article Everything About Method Overloading Vs Method Overriding , I have discussed method overloading and overriding, their rules and differences. In this article, we will see How Does JVM Handle Method Overloading And Overriding Internally, how JVM identifies which method should get called. Let’s take the example of parent class  Mammal and a child  Human classes from our previous blog to understand it more clearly. public class OverridingInternalExample { private static class Mammal { public void speak() { System.out.println("ohlllalalalalalaoaoaoa"); } } private static class Human extends Mammal { @Override public void speak() { System.out.println("Hello"); } // Valid overload of speak public void speak(String language) { if (language.equals("Hindi")) System.out.println("Namaste"); else System.out.println("Hello"); } @