Skip to content

Instantly share code, notes, and snippets.

View max-dark's full-sized avatar

Maxim Timakov max-dark

View GitHub Profile
@max-dark
max-dark / to_wstring.cpp
Created May 29, 2016 14:48
convert std::string to std::wstring
#include <cstdlib>
#include <cwchar>
#include <string>
#include <memory>
std::wstring to_wstring(const char* str) {
std::unique_ptr<wchar_t[]> tmp = nullptr;
size_t sz, len;
len = mbstowcs(nullptr, str, 0);
sz = len + 1;
@max-dark
max-dark / switch_by_string.cpp
Last active June 2, 2016 17:35
switch by string
#include <iostream>
#include <locale>
#include <string>
#include <cstdint>
#include <limits>
static_assert(sizeof(char) == sizeof(uint8_t), "char != 8 bit");
constexpr uint64_t make_cs(const char str[], std::size_t cnt, std::size_t n) noexcept {
return (
@max-dark
max-dark / field_comparer.cpp
Last active June 2, 2016 17:41
Создание массива функторов для сравнения по полям структуры
#include <functional>
#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <assert.h>
template <class type>
using compare = std::function<bool(const type&, const type&)>;
@max-dark
max-dark / pugi_test.cpp
Last active June 3, 2016 18:31
pugixml test
/*
build: g++ -std=c++11 pugi_test.cpp -o ptest -lpugixml
Used docs:
- (XPath select)[http://pugixml.org/docs/manual.html#xpath.select]
- (XPath examples)[https://msdn.microsoft.com/ru-ru/library/ms256086(v=vs.120).aspx]
*/
#include <string>
#include <iostream>
#include <pugixml.hpp>
@max-dark
max-dark / str_tool.php
Created June 24, 2016 17:18
tools for utf-8 strings
<?php
/**
* split utf-8 string to array of chars
* @param string $str
* @return array
*/
function chars_of($str) {
return preg_split('/(?<!^)(?!$)/u', $str);
}
@max-dark
max-dark / uploads.php
Created July 1, 2016 20:12
Функция-генератор для однообразного перебора загруженных файлов
<?php
/**
* Функция-генератор для однообразного перебора загруженных файлов
* Системные требования
* PHP >= 5.5.0
* @link http://php.net/manual/ru/language.generators.php
*/
/**
* Генератор для однообразного перебора загруженных файлов
@max-dark
max-dark / debug_mode.php
Created July 12, 2016 00:40
Enable all errors. Convert Errors to Exceptions
<?php
const DEBUG = true;
error_reporting(DEBUG ? E_ALL : 0);
ini_set('display_errors', DEBUG ? 'on' : 'off');
set_error_handler(function($err_no, $err_str, $err_file, $err_line ) {
if (!(error_reporting() & $err_no)) {
return;
@max-dark
max-dark / cURLWrapper.php
Last active July 12, 2016 00:59
cURLWrapper is helper class that allows to send GET/POST requests, upload files
<?php
/**
* \cURLWrapper is helper class that allows to send GET/POST requests, upload files
*
* @package cURLWrapper
* @author Maxim 'Cra3y'
* @license LGPL
* @link https://gist.github.com/max-dark/4c08575bcff9d4c6ea926cd8c9813c01
*
* Date: 12.07.16
@max-dark
max-dark / callback_form.html
Last active July 13, 2016 06:25
Bootstrap 3 Modal Dialog Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 3 Modal Dialog Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- #include <jquery-1-12> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<!-- #include <jquery-1-12> -->
<!-- #include <bootstrap-3-3> -->
@max-dark
max-dark / vzsh.php
Created July 16, 2016 17:30
v Zero Shell - simple web-based CLI
<?php
/*
________
\___ _/ ___ _ __ ___
.-. ,-, / / / _ \| .-\| / \
\ \/ / _/ /__ | __/| | | | |
\__/ /______\\___||_| \___/
______ _ ___ _ _
/ _____\| |___ / _ \| || |
\_____ \| ,-. || __/| || |