Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

handling/configuring event when tinymce editor initializes

Initialize the editor the traditional way

tinyMCE.init({
   ...
   setup : function(ed) {
      ed.onInit.add(window.testfunc);
      
   }
});

function testfunc()
{
   alert('Editor initialized');

   //set content for editor 
   var ed = tinyMCE.get('editor');
   ed.setContent(hfContent.value);//setting value from hidden field	
}

setting tinymce editor content via javascript

setting tinymce editor content via javascript

<script type="text/javascript">
    tinyMCE.get(mceId).execCommand('mceSetContent',false, '<p>some text<table></table></p>' );
</script>     

A solution for the "Graphical Editor" problem

A solution for the "Graphical Editor" problem.

Problem description:
http://icpcres.ecs.baylor.edu/onlinejudge/external/102/10267.html

Author: Joana Matos Fonseca da Trindade
Date: 2008.03.12

/* 
 * Solution for the "Graphical Editor" problem.
 * UVa ID: 10267
 */
#include <stdio.h>

#define MAX 250
#define OFFSET 1
#define DOS_NAME 12

/* global image bounds */
int n, m;

/* fills a rectangle with the specified color */
int fillRectangle(int m_ini, int n_ini, int m_end, int n_end, char color, char pTable[][MAX+OFFSET]) {
	int i, j;
	for (i = n_ini; i <= n_end; i++) {
		for (j = m_ini; j <= m_end; j++) {
			pTable[i][j] = color;
		}
	}
	return 0;
}

/* fills a region R with the specified color */
int fillRegion(int x, int y, char oldColor, char newColor, char pTable[][MAX+OFFSET]) {	
	/* (x,y) is in region R */
	pTable[y][x] = newColor;
	
	/* recursively check all 4 directions for neighbours of (x,y) with same color */
	if ((pTable[y][x-1] == oldColor) && (x > OFFSET)) {         
		fillRegion(x-1, y, oldColor, newColor, pTable);
	}
	if ((pTable[y][x+1] == oldColor) && (x < m)) {       
		fillRegion(x+1, y, oldColor, newColor, pTable);
	}
	if ((pTable[y-1][x] == oldColor) && (y > OFFSET)) {        
		fillRegion(x, y-1, oldColor, newColor, pTable);
	}
	if ((pTable[y+1][x] == oldColor) && (y < n)) {        
		fillRegion(x, y+1, oldColor, newColor, pTable);
	}
	return 0;
}

/* outputs the image */
int printImage(int m, int n, char pTable[][MAX+OFFSET]) {
	int i, j;	
	for (i = OFFSET; i < n+OFFSET; i++) {
		for (j = OFFSET; j < m+OFFSET; j++ ) {
			printf("%c", pTable[i][j]);
		}
		printf("\n");
	}
	return 0;
}

/* main */
int main (int argc, const char * argv[]) {
	/* the image */
	char image[MAX+OFFSET][MAX+OFFSET];

	/* editor command */
	char command;
	
	/* coords */
	int x1, x2, y1, y2, tmp;
	
	/* colors */
	char color, oldColor;
	
	/* filename */
	char filename[DOS_NAME+1];
			
	while(scanf("%c", &command) != EOF) {		
		/* X, terminates the session */
		if (command == 'X') {
			return 0;
		}		
		switch (command) {
			/* create image */
			case 'I' :
				scanf("%d %d", &m, &n);
				fillRectangle(1, 1, m, n, 'O', image);
				break;
			
			/* clear image */
			case 'C' :
				fillRectangle(1, 1, m, n, 'O', image);
				break;
			
			/* colors a pixel */
			case 'L' :
				scanf("%d %d %c", &x1, &y1, &color);
				image[y1][x1] = color;
				break;
			
			/* draw vertical segment */
			case 'V' :
				scanf("%d %d %d %c", &x1, &y1, &y2, &color);
				if (y2 >= y1)
					fillRectangle(x1, y1, x1, y2, color, image);
				else
					fillRectangle(x1, y2, x1, y1, color, image);
				break;
			
			/* draw horizontal segment */
			case 'H' : 
				scanf("%d %d %d %c", &x1, &x2, &y1, &color);
				if (x2 >= x1)
					fillRectangle(x1, y1, x2, y1, color, image);
				else
					fillRectangle(x2, y1, x1, y1, color, image);
				break;
			
			/* draw rectangle */
			case 'K' : 
				scanf("%d %d %d %d %c", &x1, &y1, &x2, &y2, &color);
				if (x1 >= x2) {
					tmp = x1;
					x1 = x2;
					x2 = tmp;
				}
				if (y1 >= y2) {
					tmp = y1;
					y1 = y2;
					y2 = tmp;
				}
				fillRectangle(x1, y1, x2, y2, color, image);
				break;
			
			/* fill */
			case 'F' :
				scanf("%d %d %c", &x1, &y1, &color);
				oldColor = image[y1][x1];
				if (oldColor != color) {
					fillRegion(x1, y1, oldColor, color, image);
				}
				break;

			/* fill */
			case 'S' :
				scanf("%s", &filename);
				printf("%s\n", filename);
				printImage(m, n, image);
				break;			
		
			default: 
				break;
		}		
	}
	
	return 0;
}

SciTE, my "good default options"

They should be default options of SciTE (good for python too)
just put them in your scite user properties (menu > options > open user properties)
# visual options of the gui
tabbar.hide.one=0
toolbar.visible=1
tabbar.visible=1
statusbar.visible=1
line.margin.visible=1
line.margin.width=4
buffers=20
buffers.zorder.switching=1

# editing options
braces.check=1
braces.sloppy=1
are.you.sure=1
load.on.activate=1
are.you.sure.on.reload=1
reload.preserves.undo=1

# source-respect options
strip.trailing.spaces=1
tabsize=4
indent.size=4
use.tabs=0
indent.auto=1
indent.opening=1
indent.closing=1
tab.indents=1
backspace.unindents=1
eol.mode=LF
eol.auto=1

wierd little online text editor

careful who gets access to this script. as far as i can tell this can only modify files in its own directory (although i didn't explicitly make it that way). im new at perl so careful anyway. questions or comments? (dj_bidi@fastmail.fm)

#!/usr/bin/perl

##         SLEd (Sort Of Like Ed) Editor
## USE:
##  append commands to url after a question mark 
## COMMANDS:
##  open (temp) file:                      -f,[file_to_edit]
##  close (temp)file:                      -d 
##  delete real file (careful!):           -dd
##  insert line (0 inserts at beginning):  -[line_number]a,[new_text] 
##  replace line:                          -[line_number],[new_text]
##  regex replace in line (like s///g):    -[line_number],/[old]/[new]/
##  add line:                              [line_to_add]
##  delete line:                           -[line_number]
##  save over real file:                   . 
##  save as new file:                      .[newfile_name]
## QUIRKS:
##  use ":lb:" to pass a #

$in = $ENV{'QUERY_STRING'};
$in =~ s/%3C/</g;
$in =~ s/%3E/>/g;
$in =~ s/:lb:/#/g;
$in =~ s/%20/ /g;
$in =~ s/%22/"/g;

$url = $ENV{'SCRIPT_URI'};
($name = $url) =~ s/.+\///;
$file = "~SLEd.pl";

if ($in =~ /-f,(.*)/) {
 if ($file ne "") {
  unlink "$file";
 }
 $new = $1;
 $new =~ s/;//g;
 $new =~ s/"//g;
 open (IN, "$new");
 if (length($new) != 0) { 
  open (OUT, ">~$new");
 }
 while ($_ = <IN>) {
  print OUT "$_";
 }
 close IN;
 close OUT;
 rename "$name", "~bak";
 open (IN, "~bak");
 open (OUT, ">$name");
 while ($_ = <IN>) {
  if (length($new) == 0) {
   $_ =~ s/\$file = \".*\"/\$file = \"\"/g;
  } else {
   $_ =~ s/\$file = \".*\"/\$file = \"~$new\"/g;
  } 
  print OUT "$_";
 }
 close IN;
 close OUT;
 unlink "~bak";
 print "location: $url\n\n";
 die;
}

if ($in  eq ".") {
 ($f = $file) =~ s/^~//;
 unlink "$f";
 rename("$file", "$f");
 print "location: $url?-f,\n\n";
 die;
} 

if ($in eq "-dd") {
 ($f = $file) =~ s/^~//;
 unlink "$f";
 unlink "$file";
 print "location: $url?-f,\n\n";
 die;
} 

if ($in =~ /^\.(.+)/) {
 $new = $1;
 $new =~ s/;//g;
 $new =~ s/"//g;
 ($f = $file) =~ s/^~//;
 rename("$file", "$new");
 print "location: $url?-f,\n\n";
 die;
} 

if ($in eq "-d") {
 unlink "$file";
 print "location: $url?-f,\n\n";
 die;
} 

if ($in =~ /^-([0-9]+)a,(.+)/) {
  $i = 1;
  if ($1 == 0) {
   push(@print, "$2\n");
  }
  open (F, "$file");
  while (<F>) {
   if ($i != $1) {
    push(@print, $_);
   } else {
    push(@print, $_);
    push(@print, "$2\n");
   }
   $i++;
  }
  close F; 
  open (F, ">$file");
  foreach $line(@print) {
   print F "$line";
  }
  close F;
  print "location: $url\n\n";

} elsif ($in =~ /^-([0-9]+),(.+)/) {
  $lino = $1;
  $replace = $2;
  $i = 1;
  open (F, "$file");
  while (<F>) {
   if ($i != $lino) {
    push(@print, $_);
   } elsif ($replace =~ m/^\/(.+?)\/(.*)\/$/) {
    $ol = $1;
    $newe = $2;
    ($match = $_) =~ s/$ol/$newe/g;
    push(@print, $match);
   } else {
    push(@print, "$replace\n");
   }
   $i++;
  }
  close F;  
  open (F, ">$file");
  foreach $line(@print) {
   print F "$line";
  }
  close F;
  print "location: $url\n\n";

} elsif ($in =~ /^-([0-9]+)$/) {
 $i = 1;
 open (F, "$file");
 while (<F>) {
  if ($i != $1) {
   push(@print, $_);
  }
  $i++;
 }
 close F;
 open (F, ">$file");
 foreach $line(@print) {
  print F "$line";
 }
 close F;
 print "location: $url\n\n";

} elsif ($in) {
 open (F, ">>$file");
 print F "$in\n";
 close F;
 print "location: $url\n\n";

} else {
 print "Content-type: text/plain\n\n";
 open (F, "$file");
 $i = 1;
 while (<F>) {
  print "[$i] $_";
  $i++;
 }
}
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS