Skip to content

Instantly share code, notes, and snippets.

@slwu89
slwu89 / newMac.sh
Last active September 4, 2017 03:38
newMac.sh
#!/bin/bash
echo "fixing case ignore in tab completion"
echo "set completion-ignore-case On" >> ~/.inputrc
echo "installing stuff you need"
declare -a usrDirs=(Cellar Frameworks bin etc include lib opt sbin share var bin)
@slwu89
slwu89 / stat243-unit4-regex.txt
Last active September 6, 2017 16:42
stat243-unit4-regex.txt
Sean Wu 25931748
NOTE: using pcre (php) style regex tester found at https://regex101.com
# 3.1.1
regex: \bc?a?t\s
tested successfully against string: at%t$catfdsa cat at t dsfsd $#t34 adsf209 cat435 %ty
# 3.1.2
regex: (\s|^|\b)ca+t(\s|$)
@slwu89
slwu89 / suicide.cpp
Last active December 12, 2017 20:04
logical way to do object suicide with pointers, also an example of move semantics
#include <iostream>
#include <memory.h>
#include <utility>
#include <vector>
class human;
typedef std::unique_ptr<human> human_ptr;
typedef std::vector<human_ptr> humans_obj;
class human {
@slwu89
slwu89 / prng_class.hpp
Created December 13, 2017 03:03
quick & dirty prng
#ifndef test_rng_hpp
#define test_rng_hpp
#include <random>
#include <stdio.h>
class rng_test {
public:
rng_test(const uint_least32_t &seed) : rng(seed) {
runif = std::uniform_real_distribution<double>(0,1);
@slwu89
slwu89 / singleton.cpp
Last active December 13, 2017 05:09
how to access a singleton data member from another class
#include <iostream>
class GlobalClass
{
int m_value;
static GlobalClass *s_instance;
GlobalClass(int v = 0){
std::cout << "global singleton being born at " << this << std::endl;
m_value = v;
};
@slwu89
slwu89 / suicide2.cpp
Last active December 14, 2017 17:15
more detailed version of object suicide
#include <iostream>
#include <memory>
#include <utility>
#include <string>
#include <vector>
class human;
typedef std::unique_ptr<human> human_ptr;
typedef std::vector<human_ptr> human_vector;
@slwu89
slwu89 / logging.cpp
Last active December 19, 2017 04:15
stupid simple logging; not thread safe, havent deleted copy assignment/constructor
#include <fstream>
#include <string>
#include <iostream>
/* singleton for logging */
class logger {
private:
std::ofstream output;
static logger* l_instance;
@slwu89
slwu89 / move.cpp
Created January 5, 2018 00:30
move some unique_ptr between containers
// human.hpp
#ifndef human_hpp
#define human_hpp
#include <stdio.h>
#include <string>
#include <iostream>
class human {
@slwu89
slwu89 / haversineDist.cpp
Created January 12, 2018 19:49
haversine distance from R matrices
#include <Rcpp.h>
#include <math.h>
#include <iostream>
using namespace Rcpp;
/* Convert degrees to radians */
inline double deg2rad(const double& deg){return deg*M_PI/180;};
/* Earth mean radius [km] */
const static double R_earth = 6371;
@slwu89
slwu89 / threadSafeSingleton.cpp
Created January 13, 2018 06:42
thread safe c++11 singleton
#include <iostream>
using namespace std;
class CSingleton final
{
public:
static CSingleton* GetInstance();
void set_x(const int& x_){x = x_;};
int get_x(){return x;};