Skip to content

Instantly share code, notes, and snippets.

@valitnon
Forked from jberger/blocking_paste.pl
Created October 12, 2018 21:23
Show Gist options
  • Select an option

  • Save valitnon/b1c0ae82d163cc1b9a085afa5e39c78a to your computer and use it in GitHub Desktop.

Select an option

Save valitnon/b1c0ae82d163cc1b9a085afa5e39c78a to your computer and use it in GitHub Desktop.

Revisions

  1. @jberger jberger revised this gist Oct 27, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion blocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -82,5 +82,5 @@
    %= tag label => for => 'content' => 'Paste Content'
    %= text_area 'content', class => 'form-control'
    % end
    %= submit_button class => 'btn btn-primary' => 'Paste'
    %= submit_button 'Paste' => class => 'btn btn-primary'
    % end
    2 changes: 1 addition & 1 deletion nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -88,5 +88,5 @@
    %= tag label => for => 'content' => 'Paste Content'
    %= text_area 'content', class => 'form-control'
    % end
    %= submit_button class => 'btn btn-primary' => 'Paste'
    %= submit_button 'Paste' => class => 'btn btn-primary'
    % end
  2. @jberger jberger revised this gist Oct 27, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion blocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -82,5 +82,5 @@
    %= tag label => for => 'content' => 'Paste Content'
    %= text_area 'content', class => 'form-control'
    % end
    %= tag button => type => 'submit', class=>'btn btn-primary' => 'Paste'
    %= submit_button class => 'btn btn-primary' => 'Paste'
    % end
    2 changes: 1 addition & 1 deletion nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -88,5 +88,5 @@
    %= tag label => for => 'content' => 'Paste Content'
    %= text_area 'content', class => 'form-control'
    % end
    %= tag button => type => 'submit', class=>'btn btn-primary' => 'Paste'
    %= submit_button class => 'btn btn-primary' => 'Paste'
    % end
  3. @jberger jberger revised this gist Oct 27, 2013. 2 changed files with 4 additions and 14 deletions.
    9 changes: 2 additions & 7 deletions blocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,10 @@

    use Mojolicious::Lite;
    use Mango;
    use Mango::BSON 'bson_oid';

    helper mango => sub { state $mango = Mango->new($ENV{PASTEDB}) };
    helper pastes => sub { shift->mango->db->collection('pastes') };
    helper count => sub { shift->pastes->find->count };
    helper next => sub {
    state $count = shift->count || 0;
    return $count++;
    };

    get '/' => 'submit';

    @@ -19,7 +15,6 @@
    my $content = $self->param('content')
    or return $self->redirect_to('/');
    my $doc = {
    _id => $self->next,
    title => $title,
    content => $content,
    };
    @@ -29,7 +24,7 @@

    get '/:id' => sub {
    my $self = shift;
    my $id = $self->stash('id') + 0;
    my $id = bson_oid $self->stash('id');
    my $doc = $self->pastes->find_one({ _id => $id })
    or return $self->redirect_to('/');
    $self->stash( doc => $doc );
    9 changes: 2 additions & 7 deletions nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,10 @@

    use Mojolicious::Lite;
    use Mango;
    use Mango::BSON 'bson_oid';

    helper mango => sub { state $mango = Mango->new($ENV{PASTEDB}) };
    helper pastes => sub { shift->mango->db->collection('pastes') };
    helper count => sub { shift->pastes->find->count };
    helper next => sub {
    state $count = shift->count || 0;
    return $count++;
    };

    get '/' => 'submit';

    @@ -19,7 +15,6 @@
    my $content = $self->param('content')
    or return $self->redirect_to('/');
    my $doc = {
    _id => $self->next,
    title => $title,
    content => $content,
    };
    @@ -32,7 +27,7 @@

    get '/:id' => sub {
    my $self = shift;
    my $id = $self->stash('id') + 0;
    my $id = bson_oid $self->stash('id');
    $self->render_later;
    $self->pastes->find_one({ _id => $id }, sub {
    my ($coll, $err, $doc) = @_;
  4. @jberger jberger revised this gist Oct 13, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@
    return $self->redirect_to('/') if ( $err or not $doc );
    $self->render( show => doc => $doc );
    });
    };
    } => 'show';

    app->start;

  5. @jberger jberger revised this gist Oct 12, 2013. 2 changed files with 18 additions and 6 deletions.
    12 changes: 9 additions & 3 deletions blocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -59,10 +59,16 @@
    % title $doc->{title};
    % layout 'basic';
    %= stylesheet begin
    pre.prettyprint {
    background-color:inherit;
    border:none;
    }
    % end
    %= tag h1 => $doc->{title}
    %= tag div => class => 'well' => begin
    %= tag code => class => 'prettyprint', style => 'background-color:inherit;' => begin
    %= $doc->{content}
    %= tag pre => class => 'prettyprint' => begin
    <%= $doc->{content} =%>
    % end
    % end
    %= javascript 'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js'
    @@ -82,4 +88,4 @@
    %= text_area 'content', class => 'form-control'
    % end
    %= tag button => type => 'submit', class=>'btn btn-primary' => 'Paste'
    % end
    % end
    12 changes: 9 additions & 3 deletions nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -65,10 +65,16 @@
    % title $doc->{title};
    % layout 'basic';
    %= stylesheet begin
    pre.prettyprint {
    background-color:inherit;
    border:none;
    }
    % end
    %= tag h1 => $doc->{title}
    %= tag div => class => 'well' => begin
    %= tag code => class => 'prettyprint', style => 'background-color:inherit;' => begin
    %= $doc->{content}
    %= tag pre => class => 'prettyprint' => begin
    <%= $doc->{content} =%>
    % end
    % end
    %= javascript 'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js'
    @@ -88,4 +94,4 @@
    %= text_area 'content', class => 'form-control'
    % end
    %= tag button => type => 'submit', class=>'btn btn-primary' => 'Paste'
    % end
    % end
  6. @jberger jberger revised this gist Oct 12, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@
    return $self->redirect_to('/') if ( $err or not $doc );
    $self->render( show => doc => $doc );
    });
    } => 'show';
    };

    app->start;

  7. @jberger jberger created this gist Oct 8, 2013.
    85 changes: 85 additions & 0 deletions blocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    #!/usr/bin/env perl

    use Mojolicious::Lite;
    use Mango;

    helper mango => sub { state $mango = Mango->new($ENV{PASTEDB}) };
    helper pastes => sub { shift->mango->db->collection('pastes') };
    helper count => sub { shift->pastes->find->count };
    helper next => sub {
    state $count = shift->count || 0;
    return $count++;
    };

    get '/' => 'submit';

    post '/' => sub {
    my $self = shift;
    my $title = $self->param('title') || 'Untitled';
    my $content = $self->param('content')
    or return $self->redirect_to('/');
    my $doc = {
    _id => $self->next,
    title => $title,
    content => $content,
    };
    my $oid = $self->pastes->save($doc);
    $self->redirect_to( show => id => "$oid" );
    };

    get '/:id' => sub {
    my $self = shift;
    my $id = $self->stash('id') + 0;
    my $doc = $self->pastes->find_one({ _id => $id })
    or return $self->redirect_to('/');
    $self->stash( doc => $doc );
    } => 'show';

    app->start;

    __DATA__
    @@ layouts/basic.html.ep
    <!DOCTYPE html>
    <html>
    <head>
    <title><%= title =%></title>
    %= stylesheet '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'
    </head>
    <body>
    <div class="container">
    <%= content =%>
    </div>
    </body>
    </html>
    @@ show.html.ep
    % title $doc->{title};
    % layout 'basic';
    %= tag h1 => $doc->{title}
    %= tag div => class => 'well' => begin
    %= tag code => class => 'prettyprint', style => 'background-color:inherit;' => begin
    %= $doc->{content}
    % end
    % end
    %= javascript 'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js'
    @@ submit.html.ep
    % title 'Paste your content';
    % layout 'basic';
    %= form_for '/' => role => form => method => POST => begin
    %= tag div => class => 'form-group' => begin
    %= tag label => for => 'title' => 'Title'
    %= text_field 'title', class => 'form-control'
    % end
    %= tag div => class => 'form-group' => begin
    %= tag label => for => 'content' => 'Paste Content'
    %= text_area 'content', class => 'form-control'
    % end
    %= tag button => type => 'submit', class=>'btn btn-primary' => 'Paste'
    % end
    91 changes: 91 additions & 0 deletions nonblocking_paste.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    #!/usr/bin/env perl

    use Mojolicious::Lite;
    use Mango;

    helper mango => sub { state $mango = Mango->new($ENV{PASTEDB}) };
    helper pastes => sub { shift->mango->db->collection('pastes') };
    helper count => sub { shift->pastes->find->count };
    helper next => sub {
    state $count = shift->count || 0;
    return $count++;
    };

    get '/' => 'submit';

    post '/' => sub {
    my $self = shift;
    my $title = $self->param('title') || 'Untitled';
    my $content = $self->param('content')
    or return $self->redirect_to('/');
    my $doc = {
    _id => $self->next,
    title => $title,
    content => $content,
    };
    $self->render_later;
    $self->pastes->save($doc, sub {
    my ($coll, $err, $oid) = @_;
    $self->redirect_to( show => id => "$oid" );
    });
    };

    get '/:id' => sub {
    my $self = shift;
    my $id = $self->stash('id') + 0;
    $self->render_later;
    $self->pastes->find_one({ _id => $id }, sub {
    my ($coll, $err, $doc) = @_;
    return $self->redirect_to('/') if ( $err or not $doc );
    $self->render( show => doc => $doc );
    });
    } => 'show';

    app->start;

    __DATA__
    @@ layouts/basic.html.ep
    <!DOCTYPE html>
    <html>
    <head>
    <title><%= title =%></title>
    %= stylesheet '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'
    </head>
    <body>
    <div class="container">
    <%= content =%>
    </div>
    </body>
    </html>
    @@ show.html.ep
    % title $doc->{title};
    % layout 'basic';
    %= tag h1 => $doc->{title}
    %= tag div => class => 'well' => begin
    %= tag code => class => 'prettyprint', style => 'background-color:inherit;' => begin
    %= $doc->{content}
    % end
    % end
    %= javascript 'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js'
    @@ submit.html.ep
    % title 'Paste your content';
    % layout 'basic';
    %= form_for '/' => role => form => method => POST => begin
    %= tag div => class => 'form-group' => begin
    %= tag label => for => 'title' => 'Title'
    %= text_field 'title', class => 'form-control'
    % end
    %= tag div => class => 'form-group' => begin
    %= tag label => for => 'content' => 'Paste Content'
    %= text_area 'content', class => 'form-control'
    % end
    %= tag button => type => 'submit', class=>'btn btn-primary' => 'Paste'
    % end