Skip to content

Instantly share code, notes, and snippets.

View sloria's full-sized avatar

Steven Loria sloria

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sloria on github.
  • I am sloria (https://keybase.io/sloria) on keybase.
  • I have a public key ASBdZO4CS0jaRD3dQZoIfStXBUcfe069S6IIlOJ1cC87nQo

To claim this, I am signing this object:

from copy import deepcopy
from marshmallow import Schema, fields
def PartialSchemaFactory(schema_cls):
schema = schema_cls(partial=True)
for field_name, field in schema.fields.items():
if isinstance(field, fields.Nested):
new_field = deepcopy(field)
new_field.schema.partial = True
from flask import Flask
from marshmallow import fields
from webargs.flaskparser import use_args
app = Flask(__name__)
hello_args = {
'name': fields.Str(required=True)
}
@sloria
sloria / mcomponents.js
Last active April 8, 2018 02:00
sugar for components in mithril
/**
* Provides sugar for creating a mithril component
* tweaked from @mindeavor's imlementation here: https://gist.github.com/mindeavor/25b8aa6810b244665a2e
*/
var defcomponent = function (component) {
return function(props, content) { return m.component(component, props, content); }
};
// DEFINING COMPONENTS
@sloria
sloria / poc.py
Created December 25, 2014 20:45
from smore.apispec import APISpec
spec = APISpec(
title='Swagger Petstore',
version='1.0.0',
description='This is a sample server Petstore server. You can find out more '
'about Swagger at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> '
'or on irc.freenode.net, #swagger. For this sample, you can use the api '
'key \"special-key\" to test the authorization filters',
@sloria
sloria / rcomponents.js
Last active April 8, 2018 02:00
mithril-like modules in react
/** Sugar for creating a React component from a mithril-like module. */
var defcomponent = function(module) {
var component = {
componentWillMount() {
if (module.hasOwnProperty('controller')) {
this.ctrl = new module.controller(this.props, this.props.children);
}
},
render() {
return module.view.call(this, this.ctrl, this.props, this.props.children);
@sloria
sloria / _ped
Created September 9, 2015 00:20
#compdef ped
# vim: ft=zsh sw=2 ts=2 et
_ped() {
local curcontext="$curcontext" state line
integer NORMARG
typeset -A opt_args
_arguments -C -s -n \
'(- -h --help)'{-h,--help}'[Show help message]' \
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
train = [
('I love this sandwich.', 'pos'),
('This is an amazing place!', 'pos'),
('I feel very good about these beers.', 'pos'),
('This is my best work.', 'pos'),
("What an awesome view", 'pos'),
('I do not like this restaurant', 'neg'),
import random
from nltk.corpus import movie_reviews
from textblob.classifiers import NaiveBayesClassifier
random.seed(1)
train = [
('I love this sandwich.', 'pos'),
('This is an amazing place!', 'pos'),
('I feel very good about these beers.', 'pos'),
('This is my best work.', 'pos'),