Skip to content

Instantly share code, notes, and snippets.

View Grumblesaur's full-sized avatar

James Murphy Grumblesaur

  • Arlington, VA
  • 17:39 (UTC -04:00)
View GitHub Profile
import sys
from rapidfuzz import process
# Translate typos made by rigsters989 in [GNOME] NA to
# a slightly more recognizable version of English.
def small(w, size=4):
'''Assume that Rigs probably won't spell really small words wrong.'''
return len(w) <= 4
@Grumblesaur
Grumblesaur / chances.py
Created October 8, 2020 02:52
A quick script to examine the probabilities of success in DishonoredRPG.
#!/usr/bin/python3
def result_of(pool, skill, style, focus, difficulty):
'''Calculates the number of successes and complications from
pool: a list of results from d20s
skill: a number that determine's a character's skill level
style: a number that determine's a character's style proficiency
focus: the value under which a roll counts as a double success
difficulty: the number of successes'''
comp = 0
@Grumblesaur
Grumblesaur / prototypes.py
Created November 8, 2019 20:25
Making objects in Python the wrong way.
# prototypes.py -- James Murphy
# Construct arbitrary objects with default-initialized values
# and internal member dict-storage that provides javascript-like
# object prototyping.
import collections
def define(name, *args, bases=(object,), **fields):
if set(args) & set(fields.keys()):
raise ValueError('Member name(s) duplicated.')
@Grumblesaur
Grumblesaur / persistence.py
Created March 22, 2019 02:03
when Matt Parker started writing his Python script in this video ( https://www.youtube.com/watch?v=Wim9WJeDTHQ ), I decided to pause it and write my own
import sys
import operator
from functools import reduce
def digit_product(n):
return reduce(operator.mul, map(int, list(str(n))))
def persistence(n, return_pair=False):
original = n
digits = len(str(n))
@Grumblesaur
Grumblesaur / bf2c.py
Created November 5, 2016 20:52
Brainfuck to C Transpiler
import sys
symbols = {
'>' : '++ptr;',
'<' : '--ptr;',
'+' : '++*ptr;',
'-' : '--*ptr;',
'.' : 'putchar(*ptr);',
',' : '*ptr = getchar();',
'[' : 'while(*ptr) {',
@Grumblesaur
Grumblesaur / trickortreat.py
Created October 27, 2016 07:34
trick (Python 2) or treat (C)
#include <stdio.h>/*
print'trick'
#*/
#define pass int main(){puts("treat");return 0;}
pass
while(dataForSession.next()) {
Object data[] = new Object[colNames.length];
for (int i = 0; i < data.length; i++) {
data[i] = dataForSession.getObject(i+1);
//JOptionPane.showMessageDialog(null, data[i], "Database Column", JOptionPane.INFORMATION_MESSAGE);
rows.add(data[i]); // this line of code breaks everything
}
model.addRow(data);
}
@Grumblesaur
Grumblesaur / Remember.java
Created January 28, 2016 06:59
Full source code of awful rehash class
import java.io.Serializable;
import java.util.prefs.Preferences;
import java.io.*; // Laziness
/**
* A class to abstract away storing persistent data using the java prefrences API
* and an IBM guide at ibm.com/developerworks/library/j-prefapi/
*
* Example use:
@Grumblesaur
Grumblesaur / byteAbuse.java
Created January 27, 2016 07:23
Found in a young Java fanatic's dropbox. Reinventing the ObjectOutputStream wheel.
private static void put(Preferences prefs, String key, byte[] bytes) {
final int maxBytesPerKey = byteArrLen();
final int keysNeeded = (int) Math.ceil((float) bytes.length / (float) maxBytesPerKey);
final int remainderBytes = bytes.length % maxBytesPerKey;
byte[][] splitBytes = new byte[keysNeeded][maxBytesPerKey];
splitBytes[keysNeeded-1] = new byte[remainderBytes];
for (int keyNum=0; keyNum < keysNeeded; keyNum++) {
for (int b=0; b < splitBytes[keyNum].length; b++) {
splitBytes[keyNum][b] = bytes[(keyNum * maxBytesPerKey) + b];
}
@Grumblesaur
Grumblesaur / fzbz.c
Last active November 2, 2015 06:18
Obscured and golfed fizzbuzz in C
#include "stdio.h"
#include "string.h"
#define z 122
int main(){
char f[]={70,105,z,z,0},b[]={66,117,z,z,0},i=1,B[z],g;
for(i=1;i<=100;i++){
g=0;if(i%3<1)strcpy(B,f),g=1;
if(i%5<1){if(g>0)strcat(B,b);else if(g<1)strcpy(B,b),g=1;}
if(g<1)printf("%d\n",i);
else printf("%s\n",B);