Skip to content

Instantly share code, notes, and snippets.

View MihailJP's full-sized avatar

MihailJP MihailJP

View GitHub Profile
@MihailJP
MihailJP / gist:3652275
Created September 6, 2012 06:53
Logical (not bitwise) XOR in C++
#include <iostream>
int main() {
int a = 1; int b = 2;
if ((bool)a != (bool)b)
std::cout << "a xor b -> true" << std::endl;
else
std::cout << "a xor b -> false" << std::endl;
return 0;
}
@MihailJP
MihailJP / gist:3599125
Created September 2, 2012 13:55
Lua scope test
v = "global"
do
print(v) -- "global"
local v = "local"
print(v) -- "local", of course
v = nil
print(v) -- nil, not "global"
collectgarbage("collect")
print(v) -- still nil
print (_G.v) -- of course "global"
@MihailJP
MihailJP / modulo.hpp
Created May 17, 2014 10:31
C++ modulo whose resulting sign is same as DIVISOR, not dividend
#include <stdexcept>
template<typename T> T modulo(T dividend, T divisor) {
if (divisor == static_cast<T>(0)) // division by zero is not allowed
throw std::domain_error("division by zero");
if (dividend < static_cast<T>(0)) // dividend is negative
return -((-dividend) % (-divisor));
else // dividend is non-negative
return dividend % divisor;
}
@MihailJP
MihailJP / groovy.spec
Last active August 29, 2015 14:00 — forked from kazuhisya/Makefile
%define groovy_root_dir /usr/share
Name: groovy
Version: 2.2.2
Release: 1%{?dist}
License: See: http://groovy.codehaus.org/license.html
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Group: Development/Languages/Groovy
Summary: Contains the base system for executing groovy scripts.
Source: http://dist.codehaus.org/groovy/distributions/groovy-binary-%{version}.zip