Skip to content

Instantly share code, notes, and snippets.

View jef-sure's full-sized avatar

Anton Petrusevich jef-sure

  • Germany
View GitHub Profile
#!/usr/bin/perl
use v5.14;
my $input_string;
say "Hello! Input string as \"x + y\" or \"sin x\" \n";
say 'You can use "+", "-", "*", "\", "**", "sin", "cos", "tan"';
$input_string = <STDIN>;
my ($first_arg, $second_arg, $third_arg) = split ' ', $input_string;
sub vk_api_init {
my $self = shift;
my $token = $self->db->selectrow_hashref(
"SELECT access_token,uid FROM clients_social WHERE client_id = ? and network = ?",
{Slice => {}},
$self->current_user->{id}, 'vkontakte'
);
$self->{vk_token} = $token;
my $api_point = "https://api.vk.com/method/";
return sub {
use Curses;
use strict;
use warnings;
initscr;
start_color;
init_pair(1, COLOR_BLACK, COLOR_RED);
#!/usr/bin/perl
package World::Schema;
use base qw/DBIx::Class::Schema::Loader/;
$ENV{SCHEMA_LOADER_BACKCOMPAT} = 1;
my $schema = World::Schema->connect("DBI:mysql:database=world", "world", "world1",
{PrintError => 1, RaiseError => 1, mysql_enable_utf8 => 1});
package main;
use DBIx::Connector;
use DBIx::Struct;
@jef-sure
jef-sure / bench_vec.pl
Last active November 9, 2017 15:53
vec vs hash
use strict;
use warnings;
package A;
sub new {bless [[], undef], $_[0]}
sub id {
if (@_ > 1) {
use FindBin qw($Bin);
use lib "$Bin/../lib";
use lib "$Bin/../t";
use Test::More;
use DBI;
use Time::HiRes 'time';
use Test::mysqld;
use feature 'say';
use DBIx::MysqlAsync;
@jef-sure
jef-sure / positive_int.pl
Created December 9, 2017 16:56
Check for Positive Integer entry
#!/usr/bin/perl
use B;
use Scalar::Util::LooksLikeNumber 'looks_like_number';
sub positive_int {
my $lln = looks_like_number($_[0]);
($lln == 1 || $lln & B::SVf_IOK) && $_[0] > 0;
}
for (0, "0", 123, "123", 123.45, "123.45", "yolki-palki", "nancy") {
print "$_ -> " . (positive_int($_) ? "true" : "false");
@jef-sure
jef-sure / sort-shell.pl
Last active December 16, 2017 13:11
Shell sort
#!/usr/bin/perl
use warnings;
use strict;
use feature 'say';
my @array = (5, 3, 7, 9, 2, 1, 6, 5, 3, 7, 9, 3, 4);
say "@array - initial";
use PDF::Haru;
use strict;
use warnings;
# create new document
my $pdf = PDF::Haru::New();
#$pdf->LoadTTFontFromFile("/usr/share/fonts/truetype/msttcorefonts/arial.ttf", HPDF_TRUE);
# add page
my $page = $pdf->AddPage();
# set page size and orientation
package Undef;
sub new { bless \my $a, $_[0] }
sub AUTOLOAD { Undef->new }
use overload
'""' => sub {""},
lt => sub { $_[2] ? $_[1] lt "" : "" lt $_[1] },
le => sub { $_[2] ? $_[1] le "" : "" le $_[1] },
gt => sub { $_[2] ? $_[1] gt "" : "" gt $_[1] },
ge => sub { $_[2] ? $_[1] ge "" : "" ge $_[1] },