Syntax highlighting for CCDN! yay.

permalink
#37
reece

avatar
iconiconiconiconicon
-0 
icon
 1+
18 Posts
 Posted at 16/05/2012 - 02:33:25
chevron
Updated the site and now we have syntax highlighting. Which is great!

Used GeSHi to do this. Sorting out the CSS however was a little bit of a nightmare. I could not find a any clear documentation on the CSS selectors for generated css. So while stylizing them i had to go through a process of trial and error to decipher what each selector was. Some of them however still remain a mystery, so if anyone else knows what they are and want to help label them go for it and i can update the css.

I tried to recreate the Sunburst theme for TextMate, here is what i got where the comments on the right indicate the what lexic that selector is for:

Code: CSS
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
 /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) *//* Sunburst CSS Pack for Geshi. By Reece Fowell */.bb_code_overall {        color: eee;        font: 10.2pt monospace;}.bb_code_overall .de1, .php.bb_code_overall .de2 {/*font: normal normal 1em/1.4em monospace;*/font-family:monospace; margin:0; padding:0; background:none; vertical-align:top;}.bb_code_overall  {font-family:monospace; color: #fff;}.bb_code_overall .imp {font-weight: bold; color: #f00;}.bb_code_overall li, .php.bb_code_overall .li1 {background: #1f1f1f; color: #fff;}.bb_code_overall .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}.bb_code_overall .li2 {margin-left: 10px; background: #1f1f1f; color: #fff;}.bb_code_overall .kw1 {color: #ea9c77;}                                                                                 /* if/else/for/foreach/continue/break/return/while/do/switch */.bb_code_overall .kw2 {color: #a7d462; font-weight: bold;}                                              /* class/function/public/private/protected/<?php/?> */.bb_code_overall .kw3 {color: #e1d796;}                                                                                 /* int/double/real/static including built in functions*/.bb_code_overall .kw4 {color: #4b9be8; font-weight: bold;}                                              /* null/false/true */.bb_code_overall .co1 {color: #bbb; font-style: italic;}                                                /* inline comments and comment blocks */.bb_code_overall .co2 {color: #4b9be8; font-style: italic;}                                             /* pre processor directives */.bb_code_overall .co3 {color: #f00; font-style: italic;}                                                /* UNKOWN */.bb_code_overall .co4 {color: #bbb; font-style: italic;}                                                /* DocBlocks */.bb_code_overall .coMULTI {color: #bbb; font-style: italic;}                                    /* UNKNOWN */.bb_code_overall .es0 {color: #fff; font-weight: bold;}                                                 /* UNKNOWN */.bb_code_overall .es1 {color: #eec974; font-weight: bold;}                                              /* \n\r */.bb_code_overall .es2 {color: #fff; font-weight: bold;}                                                 /* UNKNOWN */.bb_code_overall .es3 {color: #fff; font-weight: bold;}                                                 /* UNKNOWN */.bb_code_overall .es4 {color: #fff; font-weight: bold;}                                                 /* UNKNOWN */.bb_code_overall .es5 {color: #eec974; font-weight: bold; font-style: italic;}  /* \0 */.bb_code_overall .es6 {color: #fff; font-weight: bold;}                                                 /* UNKNOWN */.bb_code_overall .es_h {color: #fff; font-weight: bold;}                                                /* UNKNOWN */.bb_code_overall .br0 {color: #fff;}                                                                                    /* brackets */.bb_code_overall .sy0 {color: #ea9c77;}                                                                                 /* selectors ;,&= -> < > . -- ++ = */.bb_code_overall .sy1 {color: #ea9c77; font-weight: bold;}                                              /* ?> */.bb_code_overall .st0 {color: #75ba53;}                                                                                 /* strings */.bb_code_overall .st_h {color: #75ba53;}.bb_code_overall .nu0 {color: #4b9be8;}                                                                                 /* numbers */.bb_code_overall .nu8 {color: #4b9be8;}.bb_code_overall .nu12 {color: #4b9be8;}.bb_code_overall .nu19 {color: #4b9be8;}.bb_code_overall .me1 {color: #99caff;}                                                                                 /* methods */.bb_code_overall .me2 {color: #ac6f3b;}.bb_code_overall .re0 {color: #4b9be8;}                                                                                 /* variables */.bb_code_overall span.xtra { display:block; } 


I decided against a language prefix, but could potentially add them back in if the Sunburst theme needs tweaking for specific languages, however it would mean that i need to recreate this block of code at least 20 times to cover most of the popular languages. So if anyone would like to help to that end, by my guest. Otherwise the one theme suits all works well for the time being.

If you want to use the Sunburst CSS theme for GeSHi on your own site, go ahead and use this one. Its free for all to use.


Feel free to test this out with some code snippets if you like, test how it looks with your own language of choice and see how it looks.

Enjoy!

If its worth doing, its worth doing right.
permalink
#39
luc

avatar
iconiconiconiconicon
-0 
icon
 1+
6 Posts
 Posted at 16/05/2012 - 02:42:44
chevron
Lets see it do C++...
Code: C++
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
 #include <cstdlib> #include <ctime>#include <iostream>#include "randomc.h"#include "mother.cpp"#include "userintf.cpp" using namespace std; int main(){//ENSURE RANDOM         int32 seed = (int32)time(0);        // random seed        CRandomMother rg(seed);            // make instance of random number generator //VARIABLES         int typedice = 0, moddice = 0, roll = 0, result = 0, numdice = 0, whatroll = 0, rollmed = 0, rollmed2 = 0, rollmed3 = 0;        int rollmed4 = 1500;        char ignore; //INPUT        //Changed way this is done, so removed.        //cout << "Please enter the dice you would like to roll in the format n'd'sides, i.e. 1d20 + modifier" << endl;        //cout << "You would like to roll: ";        //cin >> numdice;        //cout << "d";        //cin >> typedice;        //cout << " + ";        //cin >> moddice;         cout << "Would you like to use a modifier?(y/n) ";        cin >> ignore;        cout << endl;        cout << "Please enter the dice you would like to roll in the format: number <d> dice [<+> modifier]" << endl;        if(ignore == 'y' || ignore == 'Y')        {                cout << "Enter your roll: ";                cin >> numdice >> ignore >> typedice >> ignore >> moddice;                cout << endl << endl << "You are rolling a " << typedice << " sided dice, and adding " << moddice << " to it." << endl << endl;        }        else        {                cout << "Enter your roll: ";                cin >> numdice >> ignore >> typedice;                cout << endl << endl << "You are rolling a " << typedice << " sided dice." << endl << endl;        }  //ENSURE RANDOM //AGAIN          rollmed2 = rg.IRandom(1,1000);        rollmed3 = rg.IRandom(1,1000);         if(rollmed2 < rollmed3)        {                rollmed = rg.IRandom(rollmed2,rollmed3);        }        else if(rollmed2 == rollmed3)        {                rollmed = rg.IRandom(rollmed2,rollmed4);        }        else        {                rollmed = rg.IRandom(rollmed3,rollmed2);        } //ROLLING          for(int i = 0; i < numdice; i++)        {                for(int j = 0; j < rollmed; j++)                {                        roll = rg.IRandom(1,typedice);                  }                 if(i == 0)                {                        result = roll;                        cout << "After first roll: ";                        cout << result << endl;                }                else                {                        whatroll = i + 1;                        cout << "Roll #" << whatroll << " is: " << roll << endl;                        result = result + roll;                        cout << "Total after roll #" << whatroll << ": ";                        cout << result << endl;                }        } //MODIFIER           if(moddice == 0)        {                //Do Nothing        }        else        {                cout << "Total before modifier: " << result << endl;                cout << "Modifier is: + " << moddice << endl;                result = result + moddice;                //Removed due to redundancy //cout << result << endl;        } //FINAL RESULT          cout << endl << "Your result is: " << result << endl << endl;         return 0;}


...and C
Code: C
12345678910111213141516171819202122232425262728293031323334353637
 #include <stdio.h>#include <stdlib.h>#include <pthread.h> void *print_message_function( void *ptr ); main(){     pthread_t thread1, thread2;     char *message1 = "Thread 1";     char *message2 = "Thread 2";     int  iret1, iret2;     /* Create independent threads each of which will execute function */      iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);     iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);      /* Wait till threads are complete before main continues. Unless we  */     /* wait we run the risk of executing an exit which will terminate   */     /* the process and all threads before the threads have completed.   */      pthread_join( thread1, NULL);     pthread_join( thread2, NULL);       printf("Thread 1 returns: %d\n",iret1);     printf("Thread 2 returns: %d\n",iret2);     exit(0);} void *print_message_function( void *ptr ){     char *message;     message = (char *) ptr;     printf("%s \n", message);}


When you do things right, people won't be sure you've done anything at all.
permalink
#40
Justin

avatar
iconiconiconiconicon
-0 
icon
 0+
9 Posts
 Posted at 16/05/2012 - 05:37:57  Edited by Justin at 16/05/2012 - 20:54:23
chevron
Here is C#(figured I would combine Luc's code snippets)
Code: C#
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
 using System;using System.Collections.Generic;using System.Threading;using System.Collections;namespace MultiThreadedRandomNumbers{    class Program    {        static Thread[] threads = new Thread[3];        static void Main(string[] args)        {            DateTime dt = DateTime.Now;            Random[] rand = new Random[3];            for (int i = 0; i < 3; i++)            {                ArrayList index = new ArrayList(1);                index.Add(i);                threads[i] = new Thread(delegate()                {                    for (int i2 = 0; i2 < 100; i2++)                    {                        switch ((int)index[0])                        {                            case 0:                                rand[(int)index[0]] = new Random(dt.Millisecond);                                int outputNum = rand[(int)index[0]].Next(0, 1000);                                Console.WriteLine("Thread 1(millisecond) Random Value: " + (outputNum + i2));                                break;                            case 1:                                rand[(int)index[0]] = new Random(dt.Second);                                int outputNum2 = rand[(int)index[0]].Next(0, 60);                                Console.WriteLine("Thread 2(second) Random Value: " + (outputNum2 + i2));                                break;                            case 2:                                rand[(int)index[0]] = new Random(dt.Minute);                                int outputNum3 = rand[(int)index[0]].Next(0, 60);                                Console.WriteLine("Thread 3(minute) Random Value: " + (outputNum3 + i2));                                break;                        }                                            }                });                threads[i].Start();                Thread.Sleep(1);            }            for (int i = 0; i < threads.Length; i++)            {                threads[i].Join();            }            Console.WriteLine("Threads completed.");            Console.ReadLine();        }     }}  


This syntax highlighting is a great feature to the site btw.

A motto about doing something right..