Skip to content

Instantly share code, notes, and snippets.

View AphonicChaos's full-sized avatar

AphonicChaos AphonicChaos

View GitHub Profile
rps = (ReportPresentation.objects
.active_for_report_type_data_type(rpdt))
from naughty import import_json
data = import_json('stuff')
print(data[0].fields)
var gameInProgress = [
{
aspidites: turn("NorthWest"),
davidg_: move("Forward")
},
{
aspidites: shoot(),
davidg_: turn(east)
}
];
data Form = Form
{ username :: String
, password :: String
, gravatar :: Image}
validate :: Form -> Maybe a
oneEach, fileType, minLength :: Validator
main = do
user <- validate Form <$> minLength 8 username
@AphonicChaos
AphonicChaos / unique.js
Created January 20, 2016 14:01
unique function in js using higher order functions instead of a for loop
function unique(arr) {
return arr.reduce((acc, x) => {
if (acc.indexOf(x) === -1) {
acc.push(x);
}
return acc;
}, []);
}
{-# Language DeriveFunctor #-}
module Command where
import Control.Monad (replicateM_)
import Control.Monad.Free
(|>) :: (Monad m) => Int -> m a -> m ()
(|>) = replicateM_
data CommandF a = MoveForward a | DestroyBlock a deriving (Functor)
frostBeam = do
water
beam
power 3
getRange
module Main where
import Turtle
programOne :: FreeTurtle
programOne = do
forward
forward
left
right
@AphonicChaos
AphonicChaos / client.py
Last active January 8, 2016 19:26
Dynamic Message Contexts
from universal.helpers import message_context
from myjobs.models import User
from seo.models import Company
u = User.objects.get(email="[email protected]")
company = Company.objects.get(name="Test Company")
invitation = u.create_invitation(company, "[email protected]")

Before

This snippet represents the code as it exists in QC now. Invitations have a send method on them which constructs an email based on the model instance's current values. The User.send_invite method was originally written as a convenience method so that view code could create and send an invitation as a one-stop shop, optionally assigning roles as necessary. Similar things have been done for the registration, myemails, and postajob apps, so nothing is novel about this approach.

My concern with it, however (despite ironically being the person who implemented it in this instance) is that it becomes ambiguous which code should be responsible for sending invitation emails. In particular, I could easily invision someone forgetting that User.send_invite exists, or deeming it inadequate as it also deals with roles, despite that field being optional. As such, one of the two methods is bound to get more advanced logic while the other bit rots. This is not simply paranoia, as they both already deal with