Skip to content

Instantly share code, notes, and snippets.

class CommentSerializer < ActiveModel::Serializer
attributes :name, :body
belongs_to :post
url [:post, :comment]
end
@gilesbowkett
gilesbowkett / newb.clj
Last active August 29, 2015 14:20
what's the best way to satisfy this Midje test?
(facts "about finding sub-words"
(fact "(sub-words) finds all possible sub-words"
(sub-words "monocarp") => ["mono",
"monoc",
"monoca",
"monocar",
"onoc",
"onoca",
"onocar",
"onocarp",
@gilesbowkett
gilesbowkett / unicode-nonsense.bash
Last active August 29, 2015 14:19
unicode nonsense in your shell
function unicode_nonsense {
if [ $? -eq 0 ]
then echo "\[\033[0;32m\]ᕕ(ᐛ)ᕗ"
else echo "\[\033[0;31m\]¯\_(ツ)_/¯"
fi
}
function muppet_prompt {
export PS1="$(unicode_nonsense)\[\033[0m\] "
}
# Create a skeleton blog post, with metadata.
#
# Example: coffee scripts/generate-blog-post.coffee -t "Hello World" -s "hello-world" -d 20150415 -a "Giles Bowkett"'
#
# Result: updates public/posts/_data.json and creates public/posts/20150415-hello-world.md
lineReader = require "line-reader"
fs = require "fs"
cliArgs = require "command-line-args"
@gilesbowkett
gilesbowkett / compiled.js
Created January 23, 2015 20:22
compiled output of IMJV against medium complexity draft 3 schema
function validate(data) {
validate.errors = null
var errors = 0
if (data !== undefined) {
if (!(typeof data === "object" && data && !Array.isArray(data))) {
errors++
if (validate.errors === null) validate.errors = []
validate.errors.push(error1)
} else {
var keys1 = Object.keys(data)
JSON Schema: draft4 (FAILED) ( subtest failures )
additionalItems ( subtest failures )
additionalItems as schema ( AssertionError: Failed 'additional items do not match schema' )
items is schema, no additionalItems
array of items with no additionalItems ( AssertionError: Failed 'additional items are not permitted' )
additionalItems as false without items
additionalItems are allowed by default
additionalProperties ( subtest failures )
additionalProperties being false does not allow other properties ( AssertionError: Failed 'an additional property is invalid' )
additionalProperties allows a schema which should validate ( AssertionError: Failed 'an additional invalid property is invalid' )
require 'rubygems'
require 'json-schema'
schema = {
"type" => "object",
"required" => ["a"],
"properties" => {
"a" => {"type" => "integer"}
}
}
var schema = Joi.object().keys({
username: Joi.string().alphanum().min(3).max(30).required(),
password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/),
access_token: [Joi.string(), Joi.number()],
birthyear: Joi.number().integer().min(1900).max(2013),
email: Joi.string().email()
}).with('username', 'birthyear').without('password', 'access_token');
description: "A simple schema, exercising very few attributes"
type: "object"
additionalProperties: false
required: ["origin", "name", "tags", "timestamp", "data"]
properties:
origin:
type: "string"
name:
type: "string"
tags: