Skip to content

Instantly share code, notes, and snippets.

View mcleary's full-sized avatar

Thales Sabino mcleary

View GitHub Profile
@mcleary
mcleary / diag_diff.rb
Created May 22, 2016 23:55
Diagonal Difference
M = [[11, 2, 4], [4, 5, 6], [10, 8, -12]]
main_diag = 0
sec_diag = 0
for i in 0..2
main_diag += M[i][i]
sec_diag += M[i][3 - i - 1]
end
@mcleary
mcleary / naive-shortest-subsegment.cpp
Last active May 24, 2016 01:00
Naive Shortest Sub-Segment
#include <cmath>
#include <cstdio>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <string>
#include <iostream>
#include <iterator>
#include <sstream>
@mcleary
mcleary / shortest-sub-segment.cpp
Created May 24, 2016 17:47
O(n) string shortest subsegment
#include <cmath>
#include <cstdio>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <iostream>
#include <iterator>
@mcleary
mcleary / meeting-schedules.cpp
Created May 25, 2016 02:35
Meeting Schedules
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
void print_timespan(int start_time, int end_time)
{
@mcleary
mcleary / connected-sets.cpp
Created May 25, 2016 15:00
Connected Sets
#include <iostream>
#include <vector>
using namespace std;
typedef vector<vector<bool>> Matrix;
int current_matrix_size = 0;
bool is_valid(Matrix& m, int i, int j)
@mcleary
mcleary / fibonacci-factor.cpp
Created May 26, 2016 13:04
Fibonacci Factor
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int numbers_count;
@mcleary
mcleary / nvidia-physx-test.cpp
Created July 11, 2016 13:31
Simple code that shows how to setup and use the NVIDIA Physx Engine.
//
// main.cpp
// PhysX-Test
//
// Created by Thales Sabino on 10/25/14.
//
//
#define _DEBUG
@mcleary
mcleary / chrono_function_timing.cpp
Created October 14, 2016 14:37
Timing a function with <chrono>
#include <iostream>
#include <thread>
#include <chrono>
void really_long_function()
{
using namespace std::chrono;
// Very cool user defined literals for duration representation
std::this_thread::sleep_for(3000ms);
@mcleary
mcleary / CMakeLists.txt
Created August 29, 2017 21:42
How to print the compiler definitions in a CMake project
get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${DirDefs} )
message( STATUS "Found Define: " ${d} )
endforeach()
#message( STATUS "DirDefs: " ${DirDefs} )
@mcleary
mcleary / template_specialization.cpp
Created August 30, 2017 09:28
Full template specialization
#include <iostream>
class Statement
{
public:
template<typename T>
T Get(int index);