Skip to content

Instantly share code, notes, and snippets.

@cppcooper
cppcooper / CDCstatsCDN.csv
Last active Apr 14, 2021
early covid numbers (Canada, BC,NB,NS)
View CDCstatsCDN.csv
Canada Pandemic
Total Recovered death recordings dead% recovered% BC.total BC.Recovered % NB.total NB.Recovered % NS.total NS.Recovered %
04-14
04-13 25680 7756 780 3.0% 30.2% 1490 926 62.1% 116 74 63.8% 473 101 21.4%
04-12 24384 7170 0.0% 29.4% 1470 905 61.6% 114 70 61.4% 445 97 21.8%
04-11 23318 6013 653 2.8% 25.8% 1445 905 62.6% 112 70 62.5% 428 95 22.2%
04-10 Second 14 days 22148 6013 0.0% 27.1% 1410 879 62.3% 112 60 53.6% 407 93 22.9%
04-09 20765 5311 509 2.5% 25.6% 1370 858 62.6% 111 53 47.7% 373 82 22.0%
04-08 19291 4653 435 2.3% 24.1% 1336 838 62.7% 108 50 46.3% 342 77 22.5%
04-07 17883 4050 381 2.1% 22.6% 1291 805 62.4% 105 39 37.1% 310 66 21.3%
@cppcooper
cppcooper / JTGraph.h
Last active Apr 14, 2021
[C++] graphs? partial copy of header
View JTGraph.h
static void DepthFirstProcNodes(JTMetaNode* jt_node, std::function<void(JTMetaNode*)> procedure){
/** Process by depth first
* 1. loop over all edges in this node
* 2. for every edge to a child (ie. edge.Right != bn_node)
* - put this child node on the top of the stack
* - go back to step 1 for the node from the top of the stack
* 3. run the provided procedure on the node
* 4. unwind stack and continue at step 2 for the node on the stack*/
for(auto jt_iter = jt_node->Edges.begin(); jt_iter != jt_node->Edges.end(); ++jt_iter) {
if(jt_node != jt_iter->Right) {
@cppcooper
cppcooper / purgehistory_core
Last active Apr 14, 2021
removes regex pattern from bash history (also deduplicates history file)
View purgehistory_core
#!/usr/bin/bash
if [ -z "$lastCMD" ]; then
if [ -z "$SHELLSTARTED" ]; then
export SHELLSTARTED="1";
else
echo -e "purgehistory_core: Error 1: \$lastCMD is empty";
fi
exit 1
elif [ ! -z "$HISTPURGEFAIL" ]; then
exit 2
@cppcooper
cppcooper / query.lua
Last active Apr 14, 2021
[Lua] dfhack dev script - devel/query.lua
View query.lua
-- Query is a script useful for finding and reading values of data structure fields. Purposes will likely be exclusive to writing lua script code.
-- Written by Josh Cooper(cppcooper) on 2017-12-21, last modified: 2020-03-08
-- Version: 2.x
local utils=require('utils')
local validArgs = utils.invert({
'help',
'unit',
'item',
'tile',
@cppcooper
cppcooper / delimiter_ctype.h
Last active Mar 26, 2020
[C++] Custom stream delimiters
View delimiter_ctype.h
struct delimiter_ctype : std::ctype<char> {
static const mask* make_table(std::string delims)
{
// make a copy of the "C" locale table
static std::vector<mask> v(classic_table(), classic_table() + table_size);
for(mask m : v){
m &= ~space;
}
for(char d : delims){
v[d] |= space;
@cppcooper
cppcooper / ssh.bash
Last active Apr 14, 2021
Attach ssh-agent to multiple terminals
View ssh.bash
#!/usr/bin/bash
windows() { [[ -n "$WINDIR" ]]; }
if ! windows; then
lock="/tmp/.lock-sshbash"
exec 3>$lock
flock --timeout 300 3 || exit 1
fi
get-agents() {
@cppcooper
cppcooper / source.cpp
Last active Apr 14, 2021
[C++] Recurse directory with
View source.cpp
#include <filesystem>
#include <iostream>
#include <regex>
#include <vector>
#include <fstream>
#include <sstream>
#pragma warning (disable : 4267)
namespace fs = std::filesystem;
void print_data(const std::vector<std::string> &lines) {
@cppcooper
cppcooper / net-shuffle.js
Last active Apr 14, 2021
Netflix 'My List' shuffle script
View net-shuffle.js
// ==UserScript==
// @name Netflix Shuffle
// @version 1.2
// @author Cooper
// @description an ok netflix shuffler
// @match https://www.netflix.com/browse/my-list
// @namespace github.com/cppcooper
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
@cppcooper
cppcooper / twofield_compare_sort.lua
Last active Apr 14, 2021
[Lua] pairs functions (sorting iteration)
View twofield_compare_sort.lua
function spairs3(t, cmp)
-- collect the keys
local keys = {}
for k,v in pairs(job_distributions) do
keys[#keys+1] = k
--print(k)
end
utils.sort_vector(keys, nil, cmp)
@cppcooper
cppcooper / region.h
Last active Apr 14, 2021
[C++] bit packing map data
View region.h
using uint32 = unsigned __int32;
#define regionWidth 4
#define regionHeight 4
class Region_Tile
{
private:
uint32* Region;
uint32 bitmask;
__int8 bit_position;