Skip to content

Instantly share code, notes, and snippets.

Giles gilesbowkett

Block or report user

Report or block gilesbowkett

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View serializer.rb
class CommentSerializer < ActiveModel::Serializer
attributes :name, :body
belongs_to :post
url [:post, :comment]
end
@gilesbowkett
gilesbowkett / newb.clj
Last active Aug 29, 2015
what's the best way to satisfy this Midje test?
View newb.clj
(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 Aug 29, 2015
unicode nonsense in your shell
View unicode-nonsense.bash
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\] "
}
View example.coffee
# 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 Jan 23, 2015
compiled output of IMJV against medium complexity draft 3 schema
View compiled.js
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)
View failed-tests.txt
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' )
View (js)on-schema.rb
require 'rubygems'
require 'json-schema'
schema = {
"type" => "object",
"required" => ["a"],
"properties" => {
"a" => {"type" => "integer"}
}
}
View joi-schema.js
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');
View trivial-schema.cson
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:
You can’t perform that action at this time.