Skip to content

Instantly share code, notes, and snippets.

View mtao's full-sized avatar

Michael Tao mtao

View GitHub Profile
@mtao
mtao / libigl_glfw_xmonad.patch
Created February 4, 2018 20:07
glfw patch for libigl on xmonad
diff --git a/src/x11_platform.h b/src/x11_platform.h
index 7b46025..b48968f 100644
--- a/src/x11_platform.h
+++ b/src/x11_platform.h
@@ -112,6 +112,7 @@ typedef struct _GLFWwindowX11
XIC ic;
GLFWbool overrideRedirect;
+ GLFWbool visuallyMapped;
#include <Eigen/Dense>
#include <mtao/types.h>
#include <mtao/eigen/stack.h>
#include <iostream>
#include <numeric>
mtao::RowVectorX<int> range(int n) {
mtao::RowVectorX<int> ret(n);
std::iota(ret.data(),ret.data()+n,0);
return ret;
@mtao
mtao / enumerate_sb_it.cpp
Created December 28, 2017 15:13
stupidly joked that ``c++ is turning into compiled python'' and was sent ``pairs = dict(enumerate([1, 5, 4, 3, 2])); print(pairs)''
#include <map>
#include <tuple>
#include <iostream>
template <typename IteratorType>
struct enumerate {
using value_type = std::pair<int,std::remove_pointer_t<IteratorType>>;
struct enum_iter {
IteratorType it;
int idx = 0;
@mtao
mtao / sb_in_range_for.cpp
Created December 27, 2017 04:21
turns out structured bindings work in ranged for loops!
#include <map>
#include <iostream>
int main() {
std::map<int,int> pairs;
pairs[0] = 1;
pairs[1] = 5;
pairs[2] = 4;
pairs[3] = 3;
@mtao
mtao / structured_bindnig_array.cpp
Created December 22, 2017 05:03
just a quick example of why structured bindings make live easier
#include <array>
#include <iostream>
int main() {
std::array<int,2> size = {640,480};
auto [w,h] = size;
std::cout << w << " " << h << std::endl;
@mtao
mtao / static_if.cpp
Created December 21, 2017 00:23
if (and presumably for) can have static variables in initialization. test is due to me trying to not pollute my namespaces with static variables with imgui Raw
#include <iostream>
void run() {
if(static bool f = false; f) {
std::cout << "true!" << std::endl;
f = false;
} else {
std::cout << "false!" << std::endl;
f = true;
@mtao
mtao / daemon.cpp
Created December 5, 2017 04:09
simple example for using cpp thread / mutex / condition_variable to toggle running a daemon in the background
#include <iostream>
#include <condition_variable>
#include <thread>
#include <chrono>
#include <mutex>
#include <atomic>
std::condition_variable activity_cv;
std::mutex activity_mutex;
std::atomic<bool> run_daemon = false;
@mtao
mtao / lhs_determined_returns.cpp
Created November 13, 2017 20:29
a bizarre (working) attempt at getting c++ to "see" the functions on the lhs of an equals sign.
#include <tuple>
#include <functional>
#include <iostream>
template <int N>
struct int_c {constexpr static int value = N;};
template <typename CallType>
void f() {};
@mtao
mtao / nqueens.cpp
Last active November 2, 2017 04:56
nqueens solver i wound up writing on the side while guiding someone thoruhg c multidimensional arrays
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <iterator>
#include <iostream>
bool is_nqueens(const std::vector<int>& pos) {
//assume row and col safety
std::set<int> diag1;
@mtao
mtao / gol_ant.c
Created October 29, 2017 17:57
game of life / langdon's ant code i wrote to help someone learning first year C
#include <stdio.h>
#include <unistd.h>
#define NUM_ROWS 50
#define NUM_COLS 50
int wrap(int i, int max) {
return ((i) % max + max) % max;
}