Skip to content

Instantly share code, notes, and snippets.

View difranco's full-sized avatar

Anthony Di Franco difranco

View GitHub Profile
@difranco
difranco / net_parser.py
Last active May 29, 2018 09:27
Petri Net parser and simulator
from lark import Lark, Transformer
grammar = r"""
%import common.WORD
%import common.INT
%import common.WS
%ignore WS
_arrow : "->" | "→"
from github import Github
from csv import DictWriter
from sys import argv
# loads the auth key from ~/.github-oauth-key
from os.path import expanduser, join
GITHUB_OAUTH_KEY = open(join(expanduser('~'),'.github-oauth-key')).read().strip()
g = Github(GITHUB_OAUTH_KEY)
reponame = argv[1]
@difranco
difranco / randrow.py
Last active February 8, 2017 21:38
script to sample random rows from a file (typically csv) with a given probability
#!/usr/bin/env python3
# Sample random lines from a file on standard input, writing to standard output
# first command line argument is probability with which to return a row that is read
# second command line argument is something evaluating to a boolean indicating whether the file has a header
# if True, the header (first line) will always be sent through to the output
# third command line argument will manually set the seed if present so as to make the results reproducible,
# else seed will come from OS-determined random source
# Usage:
from collections import defaultdict
from sys import intern
class Coder:
"""
Creates sequential ids for objects and keeps track of them
useful e.g. for filling out a matrix with info related to objects
and translating back and forth between matrix indices and the objects
"""
def next_id(self):
from pylab import *
from scipy.stats import *
num_adults = 227e6
basic_income = 7.25*40*50
labor_force = 154e6
disabled_adults = 21e6
current_wealth_transfers = 3369e9
def jk_rowling(num_non_workers):
@difranco
difranco / genki
Last active October 13, 2015 01:18
make it executable, put it in your path, and try it out
#!/bin/bash
if [ `whoami` != "root" ]
then
echo "My full name is Sudo Genki."
exit 1
fi
if [ `which vlc-wrapper` = "vlc-wrapper not found" ]
then
echo "Sudo Genki requires vlc."
@difranco
difranco / SubSeq.scala
Last active September 24, 2015 19:17
type class adding subsequence finding method to Seq
import scala.language.implicitConversions
implicit class SubSeq[T](s: Seq[T]) {
def commonSubsequence(t:Seq[T]) : Set[IndexedSeq[T]] = {
val seq1 = s
import collection.immutable.{Set,HashSet,HashMap};
var memo = new HashMap[(Int,Int),List[List[T]]]()
def retrace(c:Array[Array[Int]], i:Int, j:Int, x:IndexedSeq[T], y:IndexedSeq[T]): List[List[T]] = {
if(memo.contains(i,j)) {
Host *
# ForwardAgent no
ForwardX11 yes
ForwardX11Trusted yes
# RhostsRSAAuthentication no
# RSAAuthentication yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no