Skip to content

Instantly share code, notes, and snippets.

View kantoniak's full-sized avatar

Krzysztof (Chris) Antoniak kantoniak

View GitHub Profile
@kantoniak
kantoniak / chrono-timepoints.cpp
Created April 13, 2017 11:33
Example of std::chrono timepoints.
#include <chrono>
#include <iostream>
int main() {
auto start = std::chrono::high_resolution_clock::now();
long long some_number = 1799997;
for (unsigned i = 0; i<100000000; i++) {
some_number *= some_number;
}
@kantoniak
kantoniak / chrono-durations.cpp
Last active April 13, 2017 10:21
Example of std::chrono durations.
#include <chrono>
#include <iostream>
using namespace std::literals::chrono_literals;
int main() {
{
// Implicit casting down
auto hours = 24h;
@kantoniak
kantoniak / selenium-example.py
Created March 22, 2017 17:48
Goes to Sketchpad website and draws a pattern
#!/usr/bin/python
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
template <class T> void glBufferDataVector(GLenum target, const std::vector<T>& v, GLenum usage) {
glBufferData(target, v.size() * sizeof(T), &v[0], usage);
}
@kantoniak
kantoniak / cpp-vectors-example.cpp
Created March 20, 2017 22:38
C++ vectors fun.
#include <iostream>
#include <vector>
using namespace std;
struct test {
int a;
long b;
};
#version 330 core
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
uniform mat4 transform;
out vec3 lighting;
vec3 getFaceNormal(in vec4 v0, in vec4 v1, in vec4 v2) {
#version 330 core
layout(triangles) in;
layout(line_strip, max_vertices = 2) out;
uniform mat4 transform;
vec3 getFaceMiddle(in vec4 v0, in vec4 v1, in vec4 v2) {
return (v0.xyz + v1.xyz + v2.xyz) / 3.f;
}
@kantoniak
kantoniak / cpp-variadic-d.cpp
Last active April 15, 2023 06:52
Variadic templates example: simple logger
#include <chrono>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
using std::chrono::system_clock;
template <typename... Args>
void log(const char* format, Args... args) {
@kantoniak
kantoniak / cpp-variadic-c.cpp
Created February 27, 2017 17:35
Variadic templates example: sizeof for parameter pack
#include <iostream>
using namespace std;
void sayIt() {
// Does nothing
}
template <typename T, typename... Ts>
void sayIt(T t, Ts... ts) {
@kantoniak
kantoniak / cpp-variadic-b.cpp
Last active February 27, 2017 17:21
Moving average using variadic templates. Takes average of consecutive 3-number sequence.
#include <iostream>
using namespace std;
template <typename U1, typename U2, typename U3>
void movingAvg(U1 u1, U2 u2, U3 u3) {
cout << "AVG(" << u1 << ", " << u2 << ", " << u3 << ") = " << (u1 + u2 + u3) / 3.f << endl;
}
template <typename U1, typename U2, typename U3, typename... Ts>