Skip to content

Instantly share code, notes, and snippets.

View trcook's full-sized avatar

Tom Cook trcook

View GitHub Profile
# -*- coding: utf-8 -*-
"""
=========
tikzmagic
=========
Magics for generating figures with TikZ.
.. note::
@trcook
trcook / Put file in repo and ignore changes.md
Last active August 29, 2015 14:16
set file to be included in repo but for changes to be ignored. This is useful for making a configuration file that has sensitive data in it.

Put file in repo and ignore changes

This is good for security so you can make a template file for security keys or whatever without commiting your own keys by accident.

setup the file

First, set the file up how you want it to look in the repo:

touch <file>
subl3 <file>
@trcook
trcook / private.xml
Last active July 25, 2018 17:40
private.xml for keyremap4macbook (karabiner). This file adds a bunch of app-specific hacks that enable emacs-style navigation. Ex. using option-f to go forward one word
<?xml version="1.0"?>
<root>
<appdef>
<appname>MACVIM</appname>
<equal>org.vim.MacVim</equal>
</appdef>
<appdef>
<appname>CHROME</appname>
<equal>com.google.Chrome</equal>
</appdef>
@trcook
trcook / autocommit.sh
Created February 3, 2015 01:48
auto commit git. use fswatch to setup a file to auto-commit a git repo on file change
#!/bin/bash
# requires fswatch
fswatch -o . -e "\\.git.*"| xargs -n1 -I{} git commit -am "snapshot from autocommit_script.sh"
@trcook
trcook / latex_Tree.tex
Created January 22, 2015 03:47
This is a good basic template for drawing a tikz picture tree.
% place in preamble:
%\usetikzlibrary{trees}
%\usetikzlibrary{decorations.text}
\begin{figure}[htb]
\centering
\ffigbox[\FBwidth]{\caption{Alliance Decisions in An incomplete information framework}
\label{}}{
\begin{tikzpicture}
@trcook
trcook / dates.rb
Created December 26, 2014 23:40
an easy script to generate a list of dates for a course schedule. This prints out the dates of specified week days (in this example, monday wednesday and friday) for each week day between a start and end date.
#!/usr/bin/env ruby
require 'date'
dates=Array.new()
#end date is 'c'
c = Date.new(2015,05,07)
# start date is 'b'
b= Date.new(2015,01,12)
days_of_week=["Monday","Wednesday","Friday"]
max_weeks= ((c-b)/7).to_int
max_weeks=max_weeks.ceil+1
@trcook
trcook / gist:e3656299f7474e9d2ae6
Created December 11, 2014 15:08
remove non-printable garbage from file
tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file
# from http://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix
@trcook
trcook / index.md
Last active February 11, 2022 09:29
how to fix a bunch of nested submodules so that they are subtrees

Submodules and nested submodules

You have a project with a submodule and a nested submodule. it took me a while to figure out how to convert it to subtrees.

why convert to subtrees:

The basic reason is to convert is to make it so that deployment and installation by others is easier and doesn't create as many problems when branching.

basic steps:

The basic process to do this (there are others that involve splitting, but i found this to be easier). in a repo named with a :

@trcook
trcook / Regex filters to run:
Last active August 29, 2015 14:09
Use latex output from kramdown to set custom environments based on classes defined in kramdown.
(?# Find:)
^\ *\\begin\{\w+?\}.*%[ |\t]+class="(\w+?)".*?\n
(?# Replace:)
\\begin{\1}\n
(?# Find:)
^\ *\\end\{\w+?\}.*%[ |\t]+class="(\w+?)".*?\n
@trcook
trcook / rakefile.md
Last active February 18, 2018 10:34
Advanced Rake Rules and Conditional Rake Rules

rules matching by regex

Occassionally we want to make a rule that matches on something more complex than file extensions. If, for example files that will be prefixed with pandoc_ depend on files that do not contain the prefix.

Ex: pandoc_slides=>slides.rmd. we can make a rule that will capture this, but we need to use a lambda function to do so:

rule (%r{pandoc_.*\.md}) => lambda{|objfile| potential_source_files.find{objfile.pathmap("%{pandoc_,}n")}} do |t|
	puts "This rule gets #{t.name} from #{t.source}"
end