Skip to content

Instantly share code, notes, and snippets.

# Copyright (c) 2013 Mak Nazecic-Andrlon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@Muon
Muon / index.html
Created September 30, 2013 10:03
JSNetworkX images as nodes demo
<!DOCTYPE html>
<html>
<head>
<title>JSNetworkX images as nodes demo</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="jsnetworkx.js"></script>
</head>
<body>
<div id="canvas"></div>
<script type="text/javascript">
import struct
header = struct.Struct("<4s5sB")
unclear_chunk1 = struct.Struct("<12s1B")
unclear_chunk2 = struct.Struct("<12s1B")
unclear_chunk3 = struct.Struct("<12s1B")
unclear_chunk4 = struct.Struct("<12s1B")
unclear_chunk5 = struct.Struct("<12s1B")
def modify_tsc(filename, changes):
import xml.etree.cElementTree as ET
import operator
from pprint import pprint, pformat
# def etree_to_dict(t):
# d = {t.tag : list(map(etree_to_dict, iter(t)))}
# d.update(('@' + k, v) for k, v in t.attrib.items())
# d['text'] = t.text
# return d
@Muon
Muon / achronlanch.py
Created May 27, 2013 14:39
Analysis of Achron's units using Lanchester's square law
from __future__ import division
import csv
from collections import namedtuple
from math import ceil, sqrt
import sys
# General constants
TICKS_PER_SECOND = 18
RP_COST = 80
import struct
header = struct.Struct("<5s58s256s256s6s")
playerinfo1 = struct.Struct("<64sH")
playerinfo2 = struct.Struct("<256s4I48s")
def modify_scn(filename, changes):
with open(filename, "rb+") as scn:
data = scn.read()
@Muon
Muon / analyzeincludes.py
Last active December 11, 2015 10:38
Finds the worst includes in a C++ source tree
import subprocess
import contextlib
import os
import sys
import fnmatch
from collections import defaultdict, Counter
@contextlib.contextmanager
def chdir(dirname=None):
curdir = os.getcwd()
@Muon
Muon / gist:3875892
Created October 11, 2012 22:18
Achron economy model
"""A high-level simulation of Achron's economy."""
from __future__ import division
# Simulation time parameters
ticks_per_second = 18
simulation_length = 5 * 60
t = simulation_length * ticks_per_second
# RP constants
with open("tyc_main.dat", mode="rt") as tycho_database:
num_close = 0
for line in tycho_database:
plx = line[79:86].strip()
if line[267] != 'P' and plx and float(plx) > 200 and line[349] != 'K' and int(line[260]) <= 4:
num_close += 1
print(num_close)
@Muon
Muon / gist:2561013
Created April 30, 2012 18:43
C/C++ header guard snippet for Sublime Text 2
<snippet>
<content><![CDATA[
#ifndef ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g}
#define ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g}
$0
#endif
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->