Return to Snippet

Revision: 3509
at August 6, 2007 08:41 by iblis


Updated Code
#!/usr/bin/perl -w
use strict;
use Frontier::Client;
#
# Post a snippet (add-on for Smultron)
# perl smultron snipperl rpc  
#
# (paste the script as a New Command in Tools menu, for example: Post it)
# (then select lines of code and run the script, Tools -> Commands -> Post it)
#
# post title grabbed from first non-empty comment, if any
# tags grabbed from second non-empty comment, if any
# language set to first tag, if many of them, else set to bash
#
my $key = '';	# (your API key)

my $tempfile = '%%s'; 
die "Please select some text\n" if ($tempfile =~ /^\%\%s$/);

open(FC, "<:utf8", $tempfile);
my $title='no title yet';
my $code = '';
my $tags = '';
my $language = 'bash';
my $flag = 0;
while (<FC>) {
	if (/^\#[^!]\s*(.+)/ && $flag == 0) {
		$title = $1;
		$flag++;
	}
	elsif (/^\#[^!]\s*(.+)/ && $flag == 1) {
		$tags = $1;
		$flag++;
		if (/(\w+) (.+)/) {
			$language = $1;
			$tags = $2;
		}
	}
	$code = $code . $_;
}

my $session = Frontier::Client->new( url => 'http://snipplr.com/xml-rpc.php', debug => 0,);
my @args = ($key, $title, $code, $tags, $language);
my $result = $session->call('snippet.post', @args);

Revision: 3508
at August 5, 2007 19:15 by iblis


Initial Code
#!/usr/bin/perl -w
use strict;
use Frontier::Client;
#
# Post a snippet (add-on for Smultron)
# perl smultron snipperl rpc  
#
# (paste the script as a New Command in Tools menu, for example: Post it)
# (then select lines of code and run the script, Tools -> Commands -> Post it)
#
# post title grabbed from first non-empty comment, if any
# tags grabbed from second non-empty comment, if any
# language set to first tag, if many of them, else set to bash
#
my $key = '';	# (your API key)

open(FC, "<:utf8", '%%s');
my $title='_empty_';
my $code = '';
my $tags = '';
my $language = 'bash';
my $flag = 0;
while (<FC>) {
	if (/^\#[^!]\s*(.+)/ && $flag == 0) {
		$title = $1;
		$flag++;
	}
	elsif (/^\#[^!]\s*(.+)/ && $flag == 1) {
		$tags = $1;
		$flag++;
		if (/(\w+) (.+)/) {
			$language = $1;
			$tags = $2;
		}
	}
	$code = $code . $_;
}

my $session = Frontier::Client->new( url => 'http://snipplr.com/xml-rpc.php', debug => 0,);
my @args = ($key, $title, $code, $tags, $language);
my $result = $session->call('snippet.post', @args);

Initial URL

                                

Initial Description

                                

Initial Title
Post a snippet (add-on for Smultron)

Initial Tags
osx

Initial Language
Perl