Skip to content

Instantly share code, notes, and snippets.

View monkeymantra's full-sized avatar

Greg Rice monkeymantra

  • San Francisco, CA
View GitHub Profile
I know rappers make hits rapping bits about bitches but the bitches they're riffing are never that specific
You could say I'm prolific
and even splitting the difference
Loose lips sunk ships all up and down the pacific
Remind me your name
cuz I musta missed it
Everyone is a mystic
Everyone is a misfit
All I see are you dipshits
Tryna get on my shit list
@monkeymantra
monkeymantra / respondWithDifferentStatusCodes.scala
Created December 7, 2017 20:44
Respond to a request with a different status code based on a condition applicable to the future
def conditionalResponse[T](
successStatusCode: StatusCodes.Success = StatusCodes.OK,
errorStatusCode: StatusCodes.ServerError = StatusCodes.InternalServerError,
condition: T => Boolean,
fut: => Future[T])(implicit m: ToEntityMarshaller[T]): Route = {
onSuccess(fut) {
case result if condition(result) => complete(successStatusCode -> result)
case result => complete(errorStatusCode -> result)
}
}
Generate the following sequence:
[1, 11, 21, 1211, 111221, 312211, 13112221 ]
Starting with "1", generate a sequence of numbers that describe the previous member of the sequence.
In this example, "1" is followed by "11" because there's "one 1". Then, to describe "11", you use "21" because
there are "two 1's". The next, 1211, describes "21" because there's "1 2, and 1 1". The next is "1 1, 1 2, 2 2s, and 2 1s"
hence "111221", Which leads to "3 1, 2 2, 1 1".
def make_sequence(num_to_produce):
initial = "1"
@monkeymantra
monkeymantra / objCalc
Created February 11, 2017 20:32
Joel's
operators = ['+', '-', '*', '/']
class Expression():
def __init__(self, input_ss):
self.input_ss = input_ss
def eval(self):
for op in operators:
if op in ['+', '-']:
result = 0
@monkeymantra
monkeymantra / Calc
Created February 11, 2017 20:30
My calc solution following the multiplication stack
__author__ = 'gregrice'
from functools import reduce
from itertools import zip_longest
import operator
OPS = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}
def eval_string(calc_string):
parsed = calc_string.split(" ")
import itertools
def flatten(l):
if type(l) != list:
return l
else:
return list(itertools.chain(*map(flatten, l)))
@monkeymantra
monkeymantra / supervisor.rb
Created December 13, 2012 02:31
First attempt at a supervisord provider
# Manage services using Supervisor. Start/stop uses /sbin/service and enable/disable uses chkconfig
Puppet::Type.type(:service).provide :supervisor, :parent => :base do
desc "Supervisor: A daemontools-like service monitor written in python
"
commands :supervisord => "/usr/bin/supervisord",
:supervisorctl => "/usr/bin/supervisorctl"