Skip to content

Instantly share code, notes, and snippets.

View ifknot's full-sized avatar
💭
Get off my lawn!

ifknot ifknot

💭
Get off my lawn!
View GitHub Profile
@ifknot
ifknot / connection.h
Last active August 29, 2015 14:10
abstract connection template
/**
@class connection connection.h
@author Jeremy Thornton http://libfbp.blogspot.co.uk/
@copyright Copyright (c) 2013 Jeremy Thornton - MIT License http://opensource.org/licenses/MIT
@version 0.5
@since 0.1
*/
#ifndef fbp_connection_h
#define fbp_connection_h
@ifknot
ifknot / connection.cpp
Created November 29, 2014 16:53
component implementation
#include "component.h"
namespace fbp {
component* component::operator()() {
try {
return run();
}
catch (que::queue_closed_exception) {
return finally();
@ifknot
ifknot / cpu_relax.h
Created January 1, 2018 00:46
MCS Lock
#ifndef CPU_RELAX_H
#define CPU_RELAX_H
#include <intrin.h>
namespace sync {
inline static void cpu_relax() {
#if (COMPILER == MVCC)
@ifknot
ifknot / mcs_lock.h
Created January 1, 2018 00:50
MCS Lock
#ifndef MCS_LOCK_H
#define MCS_LOCK_H
#include <cstdint>
#include <assert.h>
#include <atomic>
#include <thread>
#include <iostream>
@ifknot
ifknot / mcs_lock.cpp
Created January 1, 2018 00:53
MCS Lock
#include "mcs_lock.h"
namespace sync {
void mcs_lock::lock() {
//to acquire the lock a thread atomically appends its own local node at the tail of the list returning tail's previous contents
auto prior_node = tail.exchange(&local_node,
std::memory_order_acquire);
if(prior_node != nullptr) {
local_node.locked = true;
@ifknot
ifknot / stopwatch.h
Last active July 4, 2020 14:08
stopwatch iodiom high precision timer for measuring software performance
/**
* @brief stopwatch idiom high precision timer for measuring software performance
* @tparam PolicyClock - std::chrono::steady_clock (default), system_clock, high_resolution_clock
*/
template<typename PolicyClock = std::chrono::steady_clock>
class stopwatch {
using clock_t = PolicyClock;
public:
@ifknot
ifknot / r_data_frame.h
Last active September 5, 2020 19:01
C++ heterogeneous container
#pragma once
#include <variant>
#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
#include <iomanip>
#include <sstream>
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
start_date = as.Date(c("2012-01-01", "2013-09-23", "2014-11-15", "2014-05-11",
"2015-03-27")),
stringsAsFactors = FALSE
)
#include <iostream>
#include "r_data_frame.h"
int main() {
std::cout << "heterogeneous container\n\n";
R::data_frame d;
heterogeneous container
id name salary start_date
0 1 Rick 623.3 2012-01-01
1 2 Dan 515.2 2013-09-23
2 3 Michelle 611 2014-11-15
3 4 Ryan 729 2014-05-11
4 5 Gary 843.25 2015-03-27
Dan earns $515.2