Skip to content

Instantly share code, notes, and snippets.

Avatar
🇷🇺

Maxim Timakov max-dark

🇷🇺
View GitHub Profile
@max-dark
max-dark / to_wstring.cpp
Created May 29, 2016
convert std::string to std::wstring
View to_wstring.cpp
#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 / restore_tree.php
Last active Apr 25, 2019
restore tree from table
View restore_tree.php
<?php
/**
* @file https://gist.github.com/max-dark/f39028cc106ed32e8ce1b55a11643b43
*/
define('ROOT_NODE', null);
/**
* восстанавливает дерево по таблице связей
* @param array $data
View switch_by_string.cpp
#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 Jun 2, 2016
Создание массива функторов для сравнения по полям структуры
View field_comparer.cpp
#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&)>;
View pugi_test.cpp
/*
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 Jun 24, 2016
tools for utf-8 strings
View str_tool.php
<?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 Jul 1, 2016
Функция-генератор для однообразного перебора загруженных файлов
View uploads.php
<?php
/**
* Функция-генератор для однообразного перебора загруженных файлов
* Системные требования
* PHP >= 5.5.0
* @link http://php.net/manual/ru/language.generators.php
*/
/**
* Генератор для однообразного перебора загруженных файлов
@max-dark
max-dark / cURLWrapper.php
Last active Jul 12, 2016
cURLWrapper is helper class that allows to send GET/POST requests, upload files
View cURLWrapper.php
<?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 / debug_mode.php
Created Jul 12, 2016
Enable all errors. Convert Errors to Exceptions
View debug_mode.php
<?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 / callback_form.html
Last active Jul 13, 2016
Bootstrap 3 Modal Dialog Example
View callback_form.html
<!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> -->