Fork me on GitHub

Posted on 13 February 2014

An example post about code insertion into posts.

Testing code snippet highlight

The following example shows how to highlight a piece of code throughout the use of pygments:

class Singleton(type):
    """Base metaclass for Singleton pattern
@see http://stackoverflow.com/a/6798042/1977778
"""
    _instances = {}
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        # If you want to run __init__ every time the class is called, add the following else condition
        # else:
        # cls._instances[cls].__init__(*args, **kwargs)
        return cls._instances[cls]

Code highlighting with redcarpet

Another snippet rendered with the most common Github code syntax:

    def strip_nonascii(self, s):
        """This method remove non-ascii chars from argument"""
        return ud.normalize('NFKD', unicode(s) ).encode('ascii','ignore')


    @db_commit
    def create_users_table(self, cursor):

        """ Check the existence of the users log table, otherwise create it """

        pass

package astrac.akka.askretry

import akka.actor._
import akka.util.Timeout
import akka.pattern.ask
import scala.concurrent.duration._
import scala.concurrent.Future

object RetryingActor {
  case class Ask[T](target: ActorRef, message: T, rate: FiniteDuration,
  maxAttempts: Int)
    case object Retry

      case class RetryException(attempts: Int) extends Exception(s"Cannot retry
      after $attempts attempts")

        def props[T] = Props[RetryingActor]
        }

Check the markdown of this example in order to fully comprehend the correct syntax.

Here you can find more detailed information.


| lessons

| jekyll and code



We <--- New Opinions Leave us a comment or a question

Rounded Image

About getshjtdone Get to know us


This Jekyll Repo was created by Antonio Trento.

Feel free to fork it and recommend any changes. Your opinion is welcome, if you have any advice or criticism on the theme, please let me know at lantoniotrento [at] gmail.com or by opening an issue on github.



Share this theme!
working hard to be helped...

Don't forget to check our latest release:

Get Shit Done Kit Pro
  • 50+ new elements
  • LESS and SASS files
  • PSD for designers
  • New Font Icons

© 2021 Getshjtdone Kit for jekyll by Antonio Trento, made with by Tim creative and jekyll bootstrap3 for a better web. Photo by Pexels