Skip to content

Instantly share code, notes, and snippets.

View Grumblesaur's full-sized avatar

James Murphy Grumblesaur

  • Arlington, VA
  • 18:52 (UTC -04:00)
View GitHub Profile
@Grumblesaur
Grumblesaur / statroll.py
Last active August 29, 2015 14:15 — forked from CptKirklnd/statroll.py
4d6 drop 1 script for d20 system character creation
from random import randint
import sys
#allow for python2 and python3 compatibility
if sys.version_info >= (3,0):
raw_input = input
#list of final attribute scores
statList = []
@Grumblesaur
Grumblesaur / statroll.lua
Last active August 29, 2015 14:15
4d6 drop 1 script for d20 system character creation
math.randomseed(os.time())
attributes = {}
for i = 0, 5, 1 do
--initialize array for current stat
stat = {};
--roll 4d6
for j = 0, 3, 1 do
stat[j] = math.random(1, 6)
@Grumblesaur
Grumblesaur / mallocsnippet.c
Last active August 29, 2015 14:18
Thanks, GNU C Library. Your comments are unrelentingly helpful.
/* mallopt options that actually do something */
#define M_TRIM_THRESHOLD -1
#define M_TOP_PAD -2
#define M_MMAP_THRESHOLD -3
#define M_MMAP_MAX -4
#define M_CHECK_ACTION -5
#define M_PERTURB -6
#define M_ARENA_TEST -7
#define M_ARENA_MAX -8
@Grumblesaur
Grumblesaur / itoa.cpp
Created April 8, 2015 03:43
From a bad code discussion on cplusplus.com
char * itoa(int i,unsigned base){
static char s[sizeof(int)*8+2];
char*t=s+sizeof(int)*8;
int sgn=i>=0?1:-1;
i/=sgn;
do*t--="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz+/"[i%base];while(i/=base,i>0);
if(sgn<0)*t='-';
else++t;
return t;
@Grumblesaur
Grumblesaur / shell.c
Created October 15, 2015 00:33
Found in a classmate's shell program's main loop
forknum = fork();
if(forknum == 0){
fprintf(stderr, "parent ");
wait(&childstatus);
}
else{
fprintf(stderr, "child ");
childstatus = 0;
exit(childstatus);
}
@Grumblesaur
Grumblesaur / dropsort.py
Last active October 28, 2015 21:02
Dropsort: Remove element of list if it is not at least as large as the maximum of the elements preceding it.
def d(l):
j=b=0;m=l[j];r=[]
for i in l:
(m,b)=[(m,0),(i,1)][i>=m]
if b>0:r+=[i]
j+=1
l[:]=r
@Grumblesaur
Grumblesaur / binvert.py
Last active October 27, 2015 21:52
Invert a string of binary characters (ASCII 1s and 0s).
lambda s:''.join(['10'[c>'0']for c in s])
@Grumblesaur
Grumblesaur / spooky.cpp
Last active November 1, 2015 00:27
Write a function that, for a given integer, will output a string of the form (n)spooky(n+2)me.
#include<sstream>
#include<string>
[](int x){std::stringstream q;q<<x<<"spooky"<<x+2<<"me";return q.str();}
@Grumblesaur
Grumblesaur / else.c
Created November 1, 2015 04:00
What are conditionals? (Some badcode found on Github)
} else {
//
# 1
print('Hello, World!')
# 2
from math import factorial as f
print(str(f(int(input()))))
# 3
def p(N):r=range(2,N);return sum(x for x in r if sum(x%d==0 for d in r)<2)