Skip to content

Instantly share code, notes, and snippets.

@ttowncompiled
ttowncompiled / template_on_actions.txt
Created July 27, 2020 15:16
Template for *_on_actions.txt file for Stellaris event modding.
# Triggers when the game starts
on_game_start = {
events = {
}
}
on_game_start_country = {
events = {
@ttowncompiled
ttowncompiled / vimrc-pi
Last active December 5, 2018 17:07
A .vimrc file for Raspberry Pis in a Pi cluster.
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
" Make sure you use a single double quote for comments
" Make sure you use a single single quote for values
" Lightline
Plug 'itchyny/lightline.vim'
@ttowncompiled
ttowncompiled / setup-pi.sh
Last active December 5, 2018 17:06
A small script to setup a Raspberry Pi in a Pi cluster.
#!/bin/bash
ENDC='\033[0m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
# update repositories, upgrade current packages, and remove deprecated packages
echo -e "${CYAN}>>> Updating, Upgrading, and Autoremoving...${ENDC}"
@ttowncompiled
ttowncompiled / TeresaStrategyPatternRose.rose
Last active October 10, 2018 14:07
A basic example of the Strategy pattern implemented in Rose.
use std::util::Random
pub abs trait MeleeAttackBehavior begin
pub abs def meleeAttack(self: &Self) -> Int
end
pub abs trait RangedAttackBehavior begin
pub abs def rangedAttack(self: &Self) -> Int
end
pub trait Melee3d6 impl MeleeAttackBehavior begin
pub def meleeAttack(self: &Melee3d6) -> Int do
let rnd := new Random()
@ttowncompiled
ttowncompiled / TeresaStrategyPattern.java
Last active October 9, 2018 02:59
A basic example of the Strategy pattern.
import java.util.Random;
public interface MeleeAttackBehavior {
public int meleeAttack();
}
public interface RangedAttackBehavior {
public int rangedAttack();
}
public class Melee3d6 implements MeleeAttackBehavior {
public int meleeAttack() {
Random rnd = new Random();
@ttowncompiled
ttowncompiled / TeresaExample.java
Created October 9, 2018 02:46
A basic example of a design issue that can be solved with the Strategy pattern.
import java.util.Random;
public abstract class Character {
private int health;
public Character(int health) {
this.health = health;
}
public boolean wound(int dmg) {
this.health = (this.health > dmg) ? this.health-dmg : 0;
return this.health == 0;
}
@ttowncompiled
ttowncompiled / hackerrank.rb
Last active September 15, 2018 13:10
Adds a set of methods to classes of Ruby to make them more applicable to algorithmic and mathematical challenges.
class Array
def prod
if self.length == 0
return 0
end
z = 1
self.each do |a_i|
z *= a_i
end
return z
@ttowncompiled
ttowncompiled / Prod.py
Last active June 14, 2018 14:58
Computes the product of the elements of A. complexity: O(n), where n is the number of elements in A.
# python 3.6.5
# from typing import List
def prod( A: List[int] ) -> int:
""" Computes the product of the elements of A. """
if A == None or len(A) == 0:
return 0
z: int = 1
for a in A:
z *= a
return z
@ttowncompiled
ttowncompiled / PrimesGen.py
Last active June 14, 2018 13:55
Generates the first N primes starting with 2. complexity: O(N**2).
# python 3.6.5
# from typing import List
def PrimesGen( N: int ) -> List[int]:
""" Generates the first N primes starting with 2. """
P: List[int] = []
i: int = 2
while len(P) < N:
is_prime: boolean = True
for p in P:
if i % p == 0:
@ttowncompiled
ttowncompiled / Primes.py
Last active June 14, 2018 13:54
Generates a complete list of primes P s.t. for all p in P, p < N. complexity: O(N**2).
# python 3.6.5
# from typing import List
def Primes( N: int ) -> List[int]:
""" Generates a complete list of primes P s.t. for all p in P, p < N. """
P: List[int] = []
A: List[int] = [ n+1 for n in range( N ) ]
for n in range( 1, N+1 ):
if A[n-1] == 1:
continue
P.append( A[n-1] )