Showing posts with label memo. Show all posts
Showing posts with label memo. Show all posts

Monday, January 23, 2017

hdd memo

Make performance tests: HD Tune
Check health of ssd: Crystal Disk Info (it doesn't work if ssd in RAID as I see; one server goes down after start of this util)

Saturday, January 21, 2017

C++ snippets memo

hand-made scope_guard without boost scope_guard & other stuff:

std::shared_ptr<void> l(nullptr, [](void*){ system("pause"); });

example of such 'scope_guard' - temp_dir which guaranteed be deleted when out of scope:

std::string temp_filename = MyGetTempFilename();
std::shared_ptr<void> l(nullptr, [temp_filename](void*){
    boost::filesystem::remove(temp_filename);
});


thread & lambda - as for me, useful pattern - especially for unit-testing:

thread to lambda:
std::thread t([](){
    std::this_thread::sleep_for(std::chrono::seconds(1));
    system("taskkill /F /IM calc.exe");
});
t.join();


shared_ptr + placement new

std::shared_ptr<boost::interprocess::interprocess_mutex>
    placement_shared_ptr(
        new(region.get_address())boost::interprocess::interprocess_mutex,
        [](boost::interprocess::interprocess_mutex* l)
        {
            l->~interprocess_mutex();;
        }
    );


boost::thread_group replace to std::thread pattern

std::vector<std::thread> my_threads;
for (size_t i = 0; i < (size_t)threads_num; ++i)
{
    my_threads.push_back(std::thread(std::bind(&MyClass::RunThread, this,
        parameters
        )));
}
for (size_t i = 0; i < my_threads.size(); i++)
{
    my_threads[i].join();
}


.

Monday, May 23, 2016

the simplest nginx cfg for sharing files

just memo - how to share directory

worker_processes  1;
error_log ./logs/error_log.log;
events {
    worker_connections 1024;
}

http {
    server {
      listen 80;
      server_name myvhost;
      access_log ./logs/access_log.log;

      location / {
        root D:/shared_dir/;
        autoindex on;
      }
    }
}

Wednesday, May 18, 2016

errno values link

Useful link with description of values 'errno' variable on linux - [link]

Tuesday, May 10, 2016

how to launch debugger when specific process start

Found way to attach automatically debugger when specific process launched:
link
and in parameter 'debugger' you can set  fullpath to ollydbg and it will work - for example: D:\tools\odbg110\OLLYDBG.EXE

Friday, May 6, 2016

asciihex to hex in perl

Found great script on stackoverflow:

my $str = <>;
$str =~ s/(..)/chr(hex($1))/eg;
print($str);



Monday, March 14, 2016

Enable telnet client on windows

Somewhy telnet client not present in windows by default (well, once I've found it present by default in one server windows, but only once).
Here are algorithm - how to install in by standard tools - link.
backuped page:

C++ on windows and linux

Once I've encounted with problem - size of some variable on linux x86-64 differs from size of same variable on windows x86-64. And some years after that I couldn't remember - was it int or long or what. So here are link about it.
backuped article:
and here are another angry post about same problem)
backuped post:


So, problem in 'long' data type.

earlier I've used special macros to get DWORD == 4 bytes on x86 windows, x86-64 windows, x86 linux & x86-64 linux:
#if defined ( _MSC_VER )
    typedef unsigned long DWORD;
#else // for g++
    typedef unsigned int DWORD;
#endif

but now I would prefer _int32_t

Sort file by lines lengths

Often I need to sort file by length of lines and always I can't remember code which is doing this.

my @elements;

while(my $line = <>){
    push @elements, $line;
}

@sorted = sort { length $a <=> length $b } @elements;

foreach my $l (@sorted){
   print($l);
}

Monday, November 16, 2015

Mysql memo

Can't remember syntax of console mysql tools (bcs of rare using). Just put it here for myself:

dump database
"C:\Program Files\MySQL\MySQL Workbench 6.2 CE\mysqldump.exe" --host="%HOSTNAME%" --user=%USERNAME% --password=%PASSWORD% --result-file="out.txt" %DATABASE_NAME%

exec sql command
"C:\Program Files\MySQL\MySQL Workbench 6.2 CE\mysql.exe" -h %HOSTNAME% -u %USERNAME% --database=%DATABASE_NAME% --password=%PASSWORD% --execute="%QUERY" >out.txt

Using password in the command line string is insecure, so, possible to leave just '--password' without value. If not not to enter '--password', mysql think you want to connect without password and prints you an error.