App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

//			printf("Str: %s\n",str);
//			free(str);
//
//			return 0;
//		}
//
// MAKE.bat
g++ my.c -o my.exe

# Try Catch in Cpp
# No throw means no catch
//
#include <iostream>
using namespace std;
int main(int,char**){
	int n = 10;
	int m = 0;
	try {
		// if( m == 0 ) throw "Division by zero condition!";
		int val = n / m;
		cout << "Divided: " << val << endl;
	}
	catch (...){
		cout << "Caught error" << endl;
	}
	cout << "DONE" << endl;
	return 0;
}

# Nested Try Catch in Cpp
# No throw means no catch
//
#include <iostream>
using namespace std;
int main(int,char**){
	int n = 10;
	int m = 0;
	int val;
	try {
		try {
			if( m == 0 ) throw "Division by zero condition!";
			val = n / m;
			cout << "Divided: " << val << endl;
		}
		catch (runtime_error& e){ cout << "Caught inner error1" << endl; }
		catch (out_of_range& e) { cout << "Caught inner error2" << endl; }
	}
	catch (...){ cout << "Caught outer error" << endl; }
	cout << "DONE" << endl;
	return 0;
}

cheats.txt  view on Meta::CPAN


# Efficient way in javascript to insert text as html (append to body)
document.querySelector('#id').insertAdjacentHTML('beforeEnd', to_add)
# (works fast, but script tags are not usable).
#
# Use this to allow using script tags
$(id).append(details_rc);

# Stack trace in javascript (js).
try {
    // Code throwing an exception
    throw new Error();
} catch(e) {
    console.log(e.stack);
}

# Javascript log function wrapper.
log (...args) {
    const verbose = false;
    if (verbose) {
        console.log(`[${this.name}]`, ...args);
    }

cheats.txt  view on Meta::CPAN

    next KEY if $Key eq '__WARN__';
    $SIG{$Key} = sub { die $Key };    ## no critic
}
#
# RUN CODE HERE
#
$ExitOverride = 0;

# Perl signal handling (eval,die,__DIE__)
# Capture STDOUT and STDERR.
# Catch die and throw to STDOUT.
perl -MApp::Pod -E '{ local *STDOUT; open STDOUT, ">", \$out or die $!; local *STDERR; open STDERR, ">>", \$err or die $!; print "print-out"; print STDERR "print-err"; local $SIG{__DIE__} = sub{ my $m = shift; chomp $m; print STDERR "<$m>" }; eval{di...
#
# Use $@ to capture eval error.
# Better than SIG{__DIE__} since sub calls may except an die
# to stop something, like Pod::Simple, which is used by Pod::LOL).
perl -Ilib -MApp::Pod -E '{ local *STDOUT; open STDOUT, ">", \$out or die $!; local *STDERR; open STDERR, ">>", \$err or die $!; print "print-out"; print STDERR "print-err"; eval{die "die\n"}; print STDERR "<$@>" if $@; print "print-out2" } say "\n[$...

# Redirect to terminal even when STDOUT and/STDERR are sent somewhere else.
perl -E 'open my $fh, ">", "/dev/tty" or die $!; close *STDOUT; say $fh "111"; say "HERE"; say $fh "123";'
111

cheats.txt  view on Meta::CPAN

## Perl Variables - %{^HOOK}
#############################################################

# Perl Variables - %{^HOOK}
As of 5.37.10,
prior to any other actions it performs,
require will check if ${^HOOK}{require__before}
contains a coderef, and if it does it will be
called with the filename form of the item being
loaded. The hook may modify $_[0] to load a
different filename, or it may throw a fatal
exception to cause the require to fail, which
will be treated as though the required code
itself had thrown an exception.
perl -E '
    use warnings;
    BEGIN{
        ${^HOOK}{require__before} = sub {
            say "here: @_";
            $_[0] =~ s/Scalar/List/;
        };
    }
    use Scalar::Util qw( reftype );
    my $v = [];

cheats.txt  view on Meta::CPAN

# Define a function to return a value (Vim)
:function Abc()
:  return "ABC"
:endfunction

# Call a function (Vim)
# () are required.
:call Abc()

# Return a value from a function (Vim)
# :call will throw away the return value
# Use your function as an expresion instead.
:echo Abc()

# Create function inline (Vim)
# Not really friendly view.
:execute "function A()\necho \"ABC\"\nendfunction"

# Silence function redefinition with "!" (Vim)
:function! ABC()
:  echo "ABC"



( run in 0.247 second using v1.01-cache-2.11-cpan-8d75d55dd25 )