Skip to content

Instantly share code, notes, and snippets.

View antonioj-mattos's full-sized avatar

Antonio Jr. Mattos antonioj-mattos

View GitHub Profile
// ==============================
// This gist is in response to
// http://programmers.stackexchange.com/questions/228939/how-to-improve-upon-blochs-builder-pattern-to-make-it-more-appropriate-for-use
//
// This is a simple bit of code to do the same thing using the Either monad (e.g. success/failure) and applicatives
// This code is (a) more generic (b) much shorter (c) more type safe
//
// Compare with the Java code at https://gist.github.com/swlaschin/9009343
// ==============================

Keybase proof

I hereby claim:

  • I am antonioj-mattos on github.
  • I am antoniojm (https://keybase.io/antoniojm) on keybase.
  • I have a public key whose fingerprint is AAF9 54B5 B2B1 6C7C 4DCB F26D FB2D A591 4C17 975B

To claim this, I am signing this object:

namespace Newtonsoft.Json.Converters
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open System
type IdiomaticDuConverter() =
inherit JsonConverter()
[<Literal>]
#Make sure 7za is installed
choco install 7zip.commandline
# Create mongodb and data directory
md $env:temp\mongo\data
# Go to mongodb dir
Push-Location $env:temp\mongo
# Download zipped mongodb binaries to mongodbdir
@antonioj-mattos
antonioj-mattos / 1 - StorageQueueMailboxProcessor.fs
Created December 6, 2015 21:45 — forked from isaacabraham/1 - StorageQueueMailboxProcessor.fs
Demonstrates how to use F# mailbox processors in conjunction with Azure Storage Queues.
/// Code to bind mailbox processors to azure storage queues.
module AzureMailboxProcessor
open System
module private Async =
let AwaitTaskEmpty = Async.AwaitIAsyncResult >> Async.Ignore
module private Option =
let fromNullable (nullable:Nullable<_>) = if nullable.HasValue then Some nullable.Value else None
let toNullable = function

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@antonioj-mattos
antonioj-mattos / decorators.py
Created November 26, 2016 17:53 — forked from carljm/decorators.py
An example of a decorator for a view that returns a TemplateResponse, modifying the template context before it is rendered.
def paginate(ctx_name):
"""
View decorator that handles pagination of a ListObject. Expects to find it
in the TemplateResponse context under the name ``ctx_name``.
This needs to not force delivery of the ListObject.
"""
def decorator(view_func):
@wraps(view_func)
@antonioj-mattos
antonioj-mattos / decorators.py
Created March 15, 2017 14:48 — forked from codeinthehole/decorators.py
Basic auth for Django snippet
import base64
from django.http import HttpResponse
from django.contrib.auth import authenticate
from django.conf import settings
def view_or_basicauth(view, request, *args, **kwargs):
# Check for valid basic auth header
if 'HTTP_AUTHORIZATION' in request.META:
@antonioj-mattos
antonioj-mattos / deployment-tool-ansible-puppet-chef-salt.md
Created April 17, 2017 16:28 — forked from jaceklaskowski/deployment-tool-ansible-puppet-chef-salt.md
Choosing a deployment tool - ansible vs puppet vs chef vs salt

Requirements

  • no upfront installation/agents on remote/slave machines - ssh should be enough
  • application components should use third-party software, e.g. HDFS, Spark's cluster, deployed separately
  • configuration templating
  • environment requires/asserts, i.e. we need a JVM in a given version before doing deployment
  • deployment process run from Jenkins

Solution

"""
Logical deletion for Django models. Uses is_void flag
to hide discarded items from queries. Overrides delete
methods to set flag and soft-delete instead of removing
rows from the database.
"""
from django.apps import apps
from django.contrib.admin.utils import NestedObjects
from django.db import models
from django.db.models import signals