Skip to content

Instantly share code, notes, and snippets.

View cppcooper's full-sized avatar

Josh Cooper cppcooper

View GitHub Profile
@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==
@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 / 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 / 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 / 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 / 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 / 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 / region.h
Last active April 14, 2021 20:03
[C++] bit packing map data
using uint32 = unsigned __int32;
#define regionWidth 4
#define regionHeight 4
class Region_Tile
{
private:
uint32* Region;
uint32 bitmask;
__int8 bit_position;
@cppcooper
cppcooper / twofield_compare_sort.lua
Last active April 14, 2021 20:02
[Lua] pairs functions (sorting iteration)
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 / 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) {