Skip to content

Instantly share code, notes, and snippets.

View scotchi's full-sized avatar

Scott Wheeler scotchi

View GitHub Profile
@scotchi
scotchi / spread.rb
Last active November 29, 2021 21:33
Very simple model to try to calculate how long it'll be before everyone on the planet has had Covid
#!/usr/bin/env ruby
require 'active_support/all'
ACTIVE_CASES = 25000000.to_f
TOTAL_WORLD_CASES = 260000000.to_f
INCUBATION_DAYS = 3
RECOVERY_DAYS = 10
WORLD_POPULATION = 8600000000
R = 1.135
@scotchi
scotchi / debut.liquid
Last active August 4, 2021 15:17
Example Directed Edge recommendation style for Shopify's "Debut" theme
<div class="page-width">
{%- for group in groups -%}
<div class="product-recommendations__inner">
<div class="section-header text-center">
<h2>{{ group.label }}</h2>
</div>
<ul class="grid grid--uniform grid--view-items">
{%- for product in group.products -%}
<li class="grid__item small--one-half medium-up--one-quarter">
{% include 'product-card-grid', max_height: 250, product: product, show_vendor: false %}
@scotchi
scotchi / podcast_exporter
Last active December 20, 2021 21:12
Tool to read the 10 oldest, downloaded episodes of all podcasts from Podcasts.app and copy them to a specified folder
#!/usr/bin/env python3
import os
import sys
import glob
import sqlite3
import datetime
import urllib.parse
import re
import shutil
@scotchi
scotchi / HostMultiOut.h
Last active December 10, 2020 14:18
Sitala's API for enabling multi-out in hosts
#ifndef HOST_MULTIOUT_H_INCLUDED
#define HOST_MULTIOUT_H_INCLUDED
#include <memory>
#include <string>
namespace Host
{
class MultiOut
{
@scotchi
scotchi / GetTrackSendInfo_Value.c
Created April 17, 2020 11:18
A demonstration of the hack needed to pull a (not-always-going-to-be-valid) pointer out of P_SRCTRACK
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int foo;
int bar;
} MediaTrack;
typedef union {
long l;
@scotchi
scotchi / set-cmake-build-dir.el
Created March 27, 2019 13:30
Sets the build directory for CMake projects to be the "build" directory below where CMakeLists.txt is
(add-hook 'c++-mode-hook
(lambda ()
(if (not (boundp 'cmake-ide-build-dir))
(let* ((cmake-lists (locate-dominating-file default-directory "CMakeLists.txt"))
(cmake-build (concat cmake-lists "build")))
(if (and cmake-lists (file-exists-p cmake-build))
(progn
(setq cmake-ide-build-dir cmake-build)
(global-set-key (kbd "s-.") 'cmake-ide-compile)))))))
@scotchi
scotchi / convert_wordpress_tables_to_utf8.rb
Last active April 15, 2020 21:54
Convert Wordpress tables to UTF-8 (when they already have UTF-8 data stored as Latin1)
#!/usr/bin/env ruby
require 'mysql2'
DATABASE, PREFIX = ARGV
client = Mysql2::Client.new(username: 'root', database: DATABASE)
tables = client.query("select table_name from information_schema.tables " +
"where table_schema='#{DATABASE}' and table_name like '#{PREFIX}%'",
as: :array).map(&:first)
@scotchi
scotchi / convert_paths_to_absolute.cmake
Last active August 17, 2017 01:05
Convert a list of paths based in the source root to absolute paths
function(convert_paths_to_absolute input output)
set(paths "")
foreach(source ${input})
get_filename_component(absolute ${source} ABSOLUTE ${CMAKE_SOURCE_DIR})
list(APPEND paths ${absolute})
endforeach()
set(${output} "${paths}" PARENT_SCOPE)
endfunction()
@scotchi
scotchi / magic-mouse-scrolling-speed.c
Created December 13, 2016 06:33
Little tool to run setuid that can be called from ~/.xinitrc
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, const char *argv[])
{
if(geteuid() != 0)
{
fprintf(stderr, "This program should be setuid or run as root.\n");
@scotchi
scotchi / convert_controller_to_strong_params.rb
Last active October 5, 2016 11:48
Tool to parse out params in usage in a Rails controller and add a line to specify which strong params are allowed
#!/usr/bin/env ruby
require 'parser/current'
module Parser
module AST
class Node
def find(type, found: [], &block)
if self.type == type && (!block || block.call(self))
found.push(self)