Skip to content

Instantly share code, notes, and snippets.

View cppcooper's full-sized avatar

Josh Cooper cppcooper

View GitHub Profile
@cppcooper
cppcooper / qemu hook.bash
Last active November 28, 2022 04:55
libvirt cpu isolation
#!/bin/bash
# To use, put in the file:
# /etc/libvirt/hooks/qemu
# remember to chmod +x
echo $1 $2
cores=$(grep -c ^processor /proc/cpuinfo)
last_core=$((cores-1))
host_cpuset="0-$last_core"
@cppcooper
cppcooper / has_a.cpp
Created March 15, 2022 06:23
member detection with templates/macro
#include <type_traits>
#define DECLARE_HASA(what) \
template<typename T, typename = int> struct has_##what : std::false_type { };\
template<typename T> struct has_##what<T, decltype((void) T::what, 0)> : std::true_type {};
DECLARE_HASA(when) //declares above statement with 'when' replacing 'what'
@cppcooper
cppcooper / CDCstatsCDN.csv
Last active April 14, 2021 19:50
early covid numbers (Canada, BC,NB,NS)
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 April 14, 2021 20:04
[C++] graphs? partial copy of header
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 April 14, 2021 19:52
removes regex pattern from bash history (also deduplicates history file)
#!/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 April 14, 2021 20:04
[Lua] dfhack dev script - devel/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 March 15, 2022 06:26
[C++] cool niche template stuff
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 February 17, 2023 21:46
Attach ssh-agent to multiple terminals
#!/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 April 14, 2021 19:57
[C++] Recurse directory with
#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 June 30, 2023 10:46
Netflix 'My List' shuffle script
// ==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==