Skip to content

Instantly share code, notes, and snippets.

#include <algorithm>
// Source
// https://www.nottingham.ac.uk/~etzpc/nz/sirds/creation.html#Subject22
static int round(int X) {
return (int)((X)+0.5);
}
static const int DPI = 72;
static float E = round(2.5 * DPI);
@njligames
njligames / External_GTest.cmake
Created April 30, 2019 01:40 — forked from ClintLiddick/External_GTest.cmake
CMake ExternalProject_Add for Google Mock (gmock) and Google Test (gtest) Libraries
find_package(Threads REQUIRED)
ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
UPDATE_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
@njligames
njligames / producer_consumer.py
Created March 4, 2019 01:30 — forked from cristipufu/producer_consumer.py
Producer-consumer problem in python
import sys
import random
import time
from threading import *
class Producer(Thread):
def __init__(self, items, can_produce, can_consume):
Thread.__init__(self)
self.items = items
self.can_produce = can_produce
@njligames
njligames / rest-server.py
Created February 10, 2019 03:53 — forked from miguelgrinberg/rest-server.py
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
// Reference: https://picoledelimao.github.io/blog/2017/01/28/eyeball-tracking-for-mouse-control-in-opencv/?fbclid=IwAR0zbPjZW5_NyXRtlkWM8oZ7BX4asTe2UOznHUTjE1ELm4uTvwzEcKHMbGs
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <ApplicationServices/ApplicationServices.h>
#include <unistd.h>
cv::Vec3f getEyeball(cv::Mat &eye, std::vector<cv::Vec3f> &circles)
@njligames
njligames / main.cpp
Last active January 6, 2019 04:20
Producer - Consumer Threading example
//
// main.cpp
// Threading_Consumer_Producer
//
// Created by James Folk on 1/5/19.
// Copyright © 2019 James Folk. All rights reserved.
//
// Thanks to: https://gist.github.com/iikuy/8115191
@njligames
njligames / install_cmake.sh
Created August 18, 2018 02:50
install and build cmake
#/usr/bin/bash
cver=3.10.0
wd=/tmp
wget -nc -P $wd https://cmake.org/files/v${cver:0:4}/cmake-$cver.tar.gz
cd $wd
tar -xf cmake-$cver.tar.gz
cd cmake-$cver
./configure
execute pathogen#infect()
call pathogen#helptags()
map <C-n> :NERDTreeToggle<CR>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
@njligames
njligames / validate_rfc_2822_email.function.php
Created April 11, 2018 12:09 — forked from felds/validate_rfc_2822_email.function.php
Checks if an email is a valid RFC 2822 email address
<?php
/**
* Checks if an email is a valid RFC 2822 email address
*
* Examples:
* <code>
* <?php
* validate_email('dev@felds.com.br'); // returns true
* validate_email('Felds Liscia <dev@felds.com.br>'); // returns false
@njligames
njligames / func.lua
Last active May 16, 2018 15:00
lua protected call
local function _xpcall(func, params)
assert((type(params) == 'table'), "input param must be a table")
status, err, ret = xpcall (func, debug.traceback, params)
assert(status, err)
assert((type(err) == 'table'), "return value must be a table")
return err
end