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 / 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 / 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 / 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 / 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 / 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 / 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 / restore_tree.php
Last active April 25, 2019 11:23
restore tree from table
<?php
/**
* @file https://gist.github.com/max-dark/f39028cc106ed32e8ce1b55a11643b43
*/
define('ROOT_NODE', null);
/**
* восстанавливает дерево по таблице связей
* @param array $data
@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;