Skip to content

Instantly share code, notes, and snippets.

View DieHertz's full-sized avatar

Andrey Mironov DieHertz

  • Tel-Aviv
View GitHub Profile
@DieHertz
DieHertz / my-first-d-program.d
Last active December 25, 2015 14:29
Generates pretty images :-)
import std.stdio : File, fwrite;
import std.math : sqrt;
struct Header {
align (1):
short bitmap = 0x4d42;
long fileSize;
int headerSize = this.sizeof;
int dataOffset = 40;
int width;
@DieHertz
DieHertz / jni-d.d
Last active December 25, 2015 16:29
import core.runtime;
import std.random;
struct JNIEnv {}
struct _jobject {}
alias _jobject* jobject;
alias int jint;
extern (C) {
void Java_Test_dinit(JNIEnv* env, jobject object) {
mat3 Transform::rotate(const float degrees, const vec3& axis) {
const float cosine = glm::cos(glm::radians(degrees));
const float one_minus_cosine = 1.0f - cosine;
const float sine = glm::sin(glm::radians(degrees));
return glm::mat3(axis.x * axis.x * one_minus_cosine + cosine,
axis.x * axis.y * one_minus_cosine + axis.z * sine,
axis.x * axis.z * one_minus_cosine - axis.y * sine,
axis.y * axis.x * one_minus_cosine - axis.z * sine,
@DieHertz
DieHertz / bf4-emblem-editor-extender.js
Last active December 28, 2015 05:09
If you like provided functionality, you should give a look to my Chrome Extension which provides same functions without the need to enter anything into the Developer Console. You can get the extension here: https://chrome.google.com/webstore/detail/battlelog-emblem-editor-e/noagedoiolkfaoaknohhepocfeooibjb
var fitAngle = function(angle) {
return angle < 0 ? angle + 360 : angle;
}
function mirrorx() {
var object = emblem.emblem.canvas.getActiveObject(),
angle = object.get('angle');
object.set('angle', fitAngle(-object.get('angle')));
object.set('flipY', !object.get('flipY'));
@DieHertz
DieHertz / typelist.cpp
Created January 14, 2014 12:02
C++11 typelists
struct NullType {};
template <typename T, typename U>
struct TypeList {
using Head = T;
using Tail = U;
};
template <typename...> struct MakeTypeList;
#ifndef type_name_h
#define type_name_h
#include <string>
#include <type_traits>
#include <typeinfo>
template<typename... T> struct type_name {
static std::string get() { return {}; }
};
#include <unordered_map>
#include <utility>
#include <iostream>
using namespace std;
template<class T1, class T2> void fill(unordered_map<T1, T2>& m) {}
template<class T1, class T2, class Key, class Value, class... Args>
void fill(unordered_map<T1, T2>& m, Key&& key, Value&& value, Args&&... args) {
#include <iostream>
using namespace std;
struct Foo {
Foo() = default;
Foo(const Foo&) { cout << "Foo::Foo(const Foo&)" << endl; }
template<class T> Foo(const T&) { cout << "Foo::Foo<T>(const T&)" << endl; }
};
#include <iostream>
using namespace std;
struct Foo {
Foo() = default;
Foo(const Foo&) { cout << "Foo::Foo(const Foo&)" << endl; }
Foo(Foo&&) { cout << "Foo::Foo(Foo&&)" << endl; }
template<class T> Foo(T&&) { cout << "Foo::Foo<T>(T&&)" << endl; }
};
decltype(t) -> T forward<T>(t) after collapsing
T& T& T& && (T& t) T& (T& t)
T&& T& T& && (T&& t) T& (T&& t) - ill-formed
T& T&& T&& && (T& t) T&& (T&& t)
T&& T&& T&& && (T&& t) T&& (T&& t)