Skip to content

Instantly share code, notes, and snippets.

View den-mentiei's full-sized avatar
⌨️
pressing buttons for a living

Denys Mentiei den-mentiei

⌨️
pressing buttons for a living
View GitHub Profile
@den-mentiei
den-mentiei / gist:5462828
Created April 25, 2013 20:24
Will output `y is uint`.
using System;
public class Program {
private static void Main(string[] args) {
int[] x = new int[10];
if (x is uint[]) {
Console.WriteLine("x is uint");
}
object y = x;
if (y is uint[]) {
@den-mentiei
den-mentiei / gist:5462920
Created April 25, 2013 20:34
C++ template-fu allowing to check classes relationship in compile-time.
typedef char (&yes)[1];
typedef char (&no)[2];
template <typename B, typename D>
struct Host {
operator B*() const;
operator D*();
};
template <typename B, typename D>
@den-mentiei
den-mentiei / gist:5463343
Created April 25, 2013 21:30
Boundary test cases for C++ comments/trigraphs parser. Courtesy by Ruslan `aruslan` Abdikeev.
// Вырезка из набора простых boundary test cases парсера C++ комментариев
// 2003-2005 (ц) Руслан "aruslan" Абдикеев
// Константы
std::cout << "C1. This is /* not a comment */\n";
std::cout << "C2. This is // not a comment\n";
std::cout << "C3. This is \" /* not a comment as well*/ \"\n";
std::cout << "C4. This is \" // not a comment as well \"\n";
std::cout << "C5. Let's print some random numbers: " << '/*' << '*/' << '\n';
std::cout << "C6. Let's print a random number: " << '//' << '\n';
@den-mentiei
den-mentiei / main.cpp
Created May 3, 2013 14:08
Variadic template type list enumerating.
#include <iostream>
using namespace std;
template <typename... T>
struct counter;
template <>
struct counter<> {
static constexpr size_t count() {
return 0;
@den-mentiei
den-mentiei / main.cpp
Created August 7, 2013 06:52
Size of int without sizeof
#include <stdio.h>
#include <stddef.h>
int main() {
int a = 0;
const size_t size = (size_t)((char*)(&a + 1) - (char*)(&a));
printf("%x", size);
return 0;
}
@den-mentiei
den-mentiei / gist:7909117
Created December 11, 2013 11:54
C++ pointer-to-member
#include <iostream>
struct A {};
struct B : virtual A {};
struct C {};
struct D : A, C {};
struct E;
int main() {
std::cout << sizeof(void (A::*)()) << std::endl;
/*
Задача такая: дано N чисел, N <= 100000, числа натуральные. Требуется: найти подмножество этих чисел, такое, что их сумма кратна N или сказать, что такого подмножества не существует.
Пример: 2 1 2 3. Ответ, например, [1,3] или [2,2] (c) mehas
*/
#include <iostream>
#include <vector>
using namespace std;
// ---- original code
// when declaring this as const, FPS drops from 30fps to 4fps on NV. wat?
int T[8] = int[8](0x15,0x38,0x32,0x2c,0x0d,0x13,0x07,0x2a);
int b0(int N, int B) { return (N>>B) & 1; }
int b(ivec3 p, int B) {
return T[b0(p.x,B)<<2 | b0(p.y,B)<<1 | b0(p.z,B)];
}
@den-mentiei
den-mentiei / StepProfiler.cs
Created July 17, 2015 11:43
Step profiler for a quick performance overiew
sealed class StepProfiler
{
private readonly Stopwatch _sw = new Stopwatch();
private long _totalTime;
private bool _started;
public void Start()
{
Debug.Assert(!_started);
Debug.Print("[!] Profiling started");
# CoffeeScript port by David Bushong <david@bushong.net>
#
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#