Skip to content

Instantly share code, notes, and snippets.

View FreeSlave's full-sized avatar

Roman Chistokhodov FreeSlave

View GitHub Profile
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 40_freebsd
Created September 6, 2016 19:01
FreeBSD grub entry for debian
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'FreeBSD' {
insmod ufs2
insmod bsd
search --fs-uuid --no-floppy --set=root *use blkid to get device UUID and insert here*
@FreeSlave
FreeSlave / nginx.conf
Last active February 18, 2023 22:48
FastDL nginx configuration for half-life server
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@FreeSlave
FreeSlave / generate_common_textures.sh
Created December 20, 2016 13:43
Generate quake3 common textures with imagemagick
#!/bin/sh
gen_texture()
{
name=$1
color1=$2
color2=$3
textcolor=$4
text=$(echo -n "$name" | tr '[:lower:]' '[:upper:]')
convert -size 64x64 xc:"$color2" -fill "$color1" -draw "rectangle 0,0 32,32" -draw "rectangle 32,32 64,64" \