Skip to content

Instantly share code, notes, and snippets.

View FreeSlave's full-sized avatar

Roman Chistokhodov FreeSlave

View GitHub Profile
@FreeSlave
FreeSlave / unzip-conv.sh
Created September 4, 2016 09:09
Unpack zip archive and convert filenames to utf-8 (e.g. if you got zip archive from Windows)
#! /bin/bash
from=
to=
if [ -z "$1" ]
then
echo "Error: no arguments"
exit 0
else
@FreeSlave
FreeSlave / only.cpp
Created August 22, 2016 13:55
Create range from single value
#include <iterator>
#include <string>
#include <cassert>
template<typename T>
struct Only
{
struct iterator : public std::iterator<std::forward_iterator_tag, T>
{
iterator(Only* only, bool isEnd = false) : _only(only), _isEnd(isEnd) {
@FreeSlave
FreeSlave / cstringiterator.cpp
Created August 19, 2016 19:26
Use STL iterators to iterate over zero terminated string without calling of strlen
// Copyright (c) 2016 Roman Chistokhodov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
/*
* Q: Why?
* A: The idea is to use STL iterators to iterate over zero terminated string without calling of strlen to evaluate the end iterator.
*
* Q: Why not random access?
* A: Currently the 'end' iterator is implemented as NULL and it's not obvious how it should work with '-' (minus) operator,
@FreeSlave
FreeSlave / call-xdg-open.c
Created August 17, 2016 13:41
Call xdg-open in C
// Copyright (c) 2016 Roman Chistokhodov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#if (defined(__linux__) && !defined __ANDROID__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__)
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <unistd.h>
#include <fcntl.h>
@FreeSlave
FreeSlave / splitter.cpp
Last active August 18, 2016 19:15
C++ Splitter implementation
// Copyright (c) 2016 Roman Chistokhodov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <string>
@FreeSlave
FreeSlave / cpucount.c
Last active September 22, 2016 13:22
Detecting number of CPU
// Copyright (c) 2016 Roman Chistokhodov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <stdio.h>
#include <stddef.h>
#if defined(__unix__) || defined(__APPLE__)
#include <unistd.h>
#endif
@FreeSlave
FreeSlave / trashcan.d
Last active June 21, 2016 15:58
Moving files to trashcan on Windows and Freedesktop in D programming language
/**
* Moving files to trashcan on Windows and Freedesktop.
* Copyright:
* Roman Chistokhodov, 2016
* License:
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
import std.path;
import std.string;