- 1
{ cat "$FETCH_LOGFILE"; cat "$PROCESSING_LOGFILE"; } >>"$SHARED_LOG"
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 116
−88
{ cat "$FETCH_LOGFILE"; cat "$PROCESSING_LOGFILE"; } >>"$SHARED_LOG"
Ma, look! I am groupinng commands!
+145
/* */
int fooBar() {
/* do something */
/* - */ return NULL;
/* + */ return 0ULL;
}
> src/foobar.c:42:3: warning: return makes integer from pointer without a cast
> return NULL;
П О Ч И Н Е Н О
−503
if (( $(true; echo $?) != 0 )); then
echo >&2 "Oops, we're running on a non-existing platform."
exit 1 # Хм, а вдруг здесь 1 == EXIT_SUCCESS?...
fi
(c) anonymous
https://www.linux.org.ru/forum/development/11317153?cid=11318931
+138
int fermat (void)
{
const int MAX = 1000;
int a=1,b=1,c=1;
while (1) {
if (((a*a*a) == ((b*b*b)+(c*c*c)))) return 1;
a++;
if (a>MAX) {
a=1;
b++;
}
if (b>MAX) {
b=1;
c++;
}
if (c>MAX) {
c=1;
}
}
return 0;
}
#include <stdio.h>
int main (void)
{
if (fermat()) {
printf ("Fermat's Last Theorem has been disproved.\n");
} else {
printf ("Fermat's Last Theorem has not been disproved.\n");
}
return 0;
}
Fermat's Last Theorem has been disproved
http://blog.regehr.org/archives/140
Если уже было черкните мне на /dev/null@localhost, удалю
−366
sub rotate {
my ($filename, $max_entries) = @_;
$max_entries //= 10; # TODO: make infinity available
return if (! -f $filename);
my ($name, $dir, $suffix) = fileparse($filename, qr/\.[^.]*$/);
my %old_files = ();
my $shift_max = 0; # maximum number of file that is going to be rotated
my $glob = File::Spec->catfile($dir, $name . '.*' . $suffix);
for my $file (glob qq/"$glob"/) {
my ($number) = $file =~ /\.(\d+)\Q$suffix\E$/;
$old_files{$number} = $file if (defined $number);
$shift_max++ while (exists $old_files{$shift_max + 1});
}
$shift_max = $max_entries - 1 if ($shift_max >= $max_entries);
# how many files to remove from the end
my $to_remove = scalar(keys %old_files) - $max_entries;
# rename and unlink
for my $number (sort { $b <=> $a } keys %old_files) {
my $file = $old_files{$number};
if ($to_remove-- > 0) {
print "## DEBUG: unlink $file\n";
unlink($file)
or croak('Cannot unlink ' . $file);
} elsif ($number <= $shift_max) {
my $new_name = File::Spec->catfile($dir, $name . '.' . ($number + 1) . $suffix);
print "## DEBUG: rename $file -> $new_name\n";
rename($file, $new_name)
or croak('Cannot rename ' . $file . ' to ' . $new_name);
}
}
my $new_name = File::Spec->catfile($dir, $name . '.1' . $suffix);
print "## DEBUG: rename $filename -> $new_name\n";
rename($filename, $new_name)
or croak('Cannot rename ' . $filename . ' to ' . $new_name);
}
Продолжаем парад велосипедов. Сделал ротацию бекап-архивов :-{
−288
sub serialize {
my ($obj) = @_;
my $result;
my $ref = ref $obj;
if ($ref eq 'HASH') {
$result = sprintf '{ %s }', join(', ', map { qq/"$_": / . serialize($obj->{$_}) } keys %$obj);
} elsif ($obj eq 'ARRAY') {
$result = sprintf '[ %s ]', join(', ', map { serialize($_) } @$obj);
} elsif (! $ref) {
if (!defined $obj) {
$result = 'null';
} elsif ($obj =~ /^ -? (?:0|[1-9]\d*) (?:\.\d+)? (?:[eE][+-]?\d+)? $/x) {
$result = $obj;
} else {
$obj =~ s/(["\\])/\\$1/g;
$obj =~ s/\r/\\r/g;
$obj =~ s/\n/\\n/g;
$obj =~ s/\t/\\t/g;
$result = qq/"$obj"/;
}
}
return $result;
}
В продолжение #17106. Самопальная Самобытная сериализация в JSON.
−155
open (FILE, "< /etc/info_file");
while (<FILE>) {
$found++ if (/^\/usr\s+/);
}
close FILE;
if ($found) {
print "# Found /usr entry in /etc/info_file\n" if ($do_debug);
} else {
print "# Adding /home entry to /etc/info_file\n" if ($do_debug);
open (FILE, ">> /etc/auto_master");
print FILE "/usr auto_usr -noview";
close FILE;
}
Энтерпрайз! Махровый и беспощадный.
−161
sub check_license {
my ($license) = @_;
my $is_valid = 0;
if (-f $license) {
open(my $fh, '<', $license);
my $content = do { local $/ = undef; <$fh> };
close($fh);
$content =~ s/\r\n/\n/g;
$is_valid = $content =~ /^-{5}BEGIN LICENSE-{5}$/m;
$is_valid = $content =~ /^-{5}END LICENSE-{5}$/m;
}
return $is_valid;
}
Ну ок.
−128
local sql=$(printf 'SELECT count(table_name) FROM user_tables WHERE table_name in (%s)' "$str_tables")
Ънтерпрайз ашпрёт
+1
for (conn_vector::iterator i = m_connections.begin(); i != m_connections.end(); ++i) {
if (*i == conn) {
m_connections.erase(i);
toDelete = *i;
break;
}
}
Да, С++98. Да, в std::find не умеем. Да, сегфолт. Да, моё.